PDA

View Full Version : No Object named DbProvider is defined


dabi
06-05-2007, 04:51 PM
Hi,
I am new to Spring.Net Framework. I am trying out the example: Spring.DataQuickStart.2005. I wrote a web app that would simply invoke the methods on Spring.DataQuickStart and display the results on the browser.
I added the following section to the web.config file of the asp.net web application:
<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"/>
<section name="parsers" type="Spring.Context.Support.ConfigParsersSectionHandler , Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<parsers>
<parser namespace="http://www.springframework.net/database" type="Spring.Data.DatabaseConfigParser, Spring.Data" schemaLocation="assembly://Spring.Data/Spring.Data/spring-database.xsd"/>
</parsers>
<context>
<resource uri="assembly://Spring.DataQuickStart.Tests/Spring.DataQuickStart.GenericTemplate/ExampleTests.xml"/>
</context>
</spring>
</configuration>

In my code behind when I use the following statement:

IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.DataQuickStart.Tests/Spring.DataQuickStart.GenericTemplate/ExampleTests.xml");

to instantiate the XmlApplicationContext object, it gives me the following error:


Spring.Objects.Factory.NoSuchObjectDefinitionExcep tion: No object named 'dbProvider' is defined : Cannot find definition for object [dbProvider]
at Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Type requiredType, Object[] arguments) in j:\release\Spring.Net\src\Spring\Spring.Core\Objec ts\Factory\Support\AbstractObjectFactory.cs:line 234
at Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Object[] arguments) in j:\release\Spring.Net\src\Spring\Spring.Core\Objec ts\Factory\Support\AbstractObjectFactory.cs:line 1242
at Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name) in j:\release\Spring.Net\src\Spring\Spring.Core\Objec ts\Factory\Support\AbstractObjectFactory.cs:line 1202
at Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ResolveReference(IConfigurableOb jectDefinition definition, String name, String argumentName, RuntimeObjectReference reference) in j:\release\Spring.Net\src\Spring\Spring.Core\Objec ts\Factory\Support\AbstractAutowireCapableObjectFa ctory.cs:line 1717


I don't know where I am going wrong.
Please help

Thanks
Dabi

Bruno Baia
06-05-2007, 07:02 PM
Hi,

There is 2 ways for configuring Spring :

---------------------------------------

Using application configuration files (app.config / web.config) :

<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"/>
<section name="parsers" type="Spring.Context.Support.ConfigParsersSectionH andler, Spring.Core" />
</sectionGroup>
</configSections>

<spring>
<parsers>
<parser type="Spring.Data.DatabaseConfigParser, Spring.Data" />
</parsers>

<context>
<resource uri="myConfiguration.xml"/>
</context>
</spring>
</configuration>

You need to use Spring.Context.ContextRegistry to get the IApplicationContext instance :

IApplicationContext context = ContextRegistry.GetContext();


---------------------------------------

Programmatically :
Using the XmlApplicationContext, but you need to register the namespace parser by the code too :

using Spring.Objects.Factory.Xml;
using Spring.Data;
using Spring.Context;
using Spring.Context.Support;

XmlParserRegistry.RegisterParser(typeof(DatabaseCo nfigParser));
IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.DataQuickStart.Tests/Spring.DataQuickStart.GenericTemplate/ExampleTests.xml");


---------------------------------------

You are mixing both ways to configure, that's why you got the error.

HTH,
Bruno

dabi
06-05-2007, 08:07 PM
Got it!

Thanks

Bruno Baia
06-06-2007, 10:25 PM
Hi dabi,

There is an error in the Spring.DataQuickStart 1.1 M1 example, but you got it now !
See this thread :
Fix for Spring.DataQuickStart 1.1 M1 example (http://forum.springframework.net/showthread.php?t=2889)

Bruno