View Full Version : Error instantiating context 'spring.root' ??? Error with ressource
Hi,
i'm new in using Spring ant want to get my first project running..
When want to compile it using VS2005, i always get the error:
Error instantiating context 'spring.root'.
the main looks like this:
IApplicationContext ctx = ContextRegistry.GetContext();
Lister.MovieLister ml = (Lister.MovieLister)ctx.GetObject("Lister");
foreach (Data.Movie ls in ml.moviesWith("willis"))
{
Console.WriteLine(ls.Title);
}
The app.config looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context name="spring.root"> <!--HERE SHOULD BE THE ERROR-->
<resource uri="assembly://MovieSpringApp/MovieSpringApp.config/applicationcontext.xml"/>
</context>
</spring>
</configuration>
Could somebody explain me the error, and tell me how to use an special file for spring configuration...
this mean to change the ressource tag:
<ressource uri="assembly://...>
or
<ressource uri="file://...>
Thanks a lot,
winx
Hi winx!
Do not panic! :)
Your config file is ok except path assembly://MovieSpringApp/MovieSpringApp.config/applicationcontext.xml. Check this path. I think error behind it (Is applicationcontext.xml embeded resource?).
To use special file for spring configuration you need to replace
<resource uri="assembly://MovieSpringApp/MovieSpringApp.config/applicationcontext.xml"/> with <resource uri="~/applicationcontext.xml" />, for example.
It allows you change configuration without compilation.
Best regards,
Nop.
Hi Nop,
the config file is in my assembly, in namespace MovieSpringApp.config.applicationcontext.xml and marked
as embedded.
I've also tried to use only the app.config with same settings,
except this:
<context name="spring.root">
<resource uri="config://spring/objects"/>
</context>
and included the <objects> secion in the app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context name="spring.root">
<resource uri="config://spring/objects"/>
</context>
<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id ="Finder" type="MovieSpringApp.Finder.MovieFinder, MovieSpringApp"/>
<object id="Lister" type="MovieSpringApp.Lister.MovieLister, MovieSpringApp">
<property name="Finder" ref="finder"/>
</object>
</objects>
</spring>
</configuration>
i've tried this, but got the same problem...
do you have another idea?
I think of en VS2005 configuration error, or something like this...
Thanks a lot,
winx
Bruno Baia
03-30-2007, 01:07 PM
Hi,
please see the full stack trace and find inner exceptions to get more infos.
About resource handlers, see reference documentation :
Chapter 6. The IResource abstraction (http://www.springframework.net/doc-latest/reference/html/resources.html#d0e4802)
file://~/objects.xml
file://objects.xml
file:///C:/Temp/objects.xml
Bruno
Hi,
i'll try this.
I used the same app.config in another spring application and: it works!!!
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler , Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context name="spring.root">
<resource uri="config://spring/objects"/>
</context>
<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
</object>
</objects>
</spring>
</configuration>
But if if copied it back to my application, the error occurs again.
Is there something about renaming the MovieApp.exe.config or changing something else inside or outside the project???
Thx
Bruno Baia
03-31-2007, 02:01 PM
Hi,
<context name="spring.root">
"spring.root" is the default context name, you don't need to specify it.
<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
</object>
</objects>
What is doing the </object> tag here ?
you can simplify this with :
<objects xmlns="http://www.springframework.net">
</objects>
To get intellisense, be sure the spring-objects.xsd is installed into VS.
See reference documentation about this :
Chapter 24. Visual Studio.NET Integration (http://www.springframework.net/doc-latest/reference/html/vsnet.html)
<object id ="Finder" type="MovieSpringApp.Finder.MovieFinder, MovieSpringApp"/>
<object id="Lister" type="MovieSpringApp.Lister.MovieLister, MovieSpringApp">
<property name="Finder" ref="finder"/>
to get this working, you need to have MovieSpringApp.exe and MovieSpringApp.exe.config in your bin directory.
You don't need to rename the .config file, "app.config" is automatically renamed to "<assemblyname>.exe.config".
HTH,
Bruno
Hi,
thanks for your answer.
I've now founded he problem, it's located here:
<objects xmlns="http://www.springframework.net">
<object id ="Finder" type="MovieSpringApp.Finder.MovieFinder, MovieSpringApp"/>
<object id="Lister" type="MovieSpringApp.Lister.MovieLister, MovieSpringApp">
<property name="Finder" ref="finder"/>
</object>
</objects>
In the source Code, the property is written like this: Finder
I've changed this and the problem is solved :)
Thanks a lot...
Now i'm trying to integrate hibernate.net into my system
Greets,
winx
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.