Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: database:dbProvider : element is not declared.

  1. #1
    Join Date
    Apr 2006
    Posts
    11

    Default database:dbProvider : element is not declared.

    Hello,

    I use spring with hibernate for a few months, everything works fine with spring 1.1.0.2 when I declare the db provider as follow :

    <objects xmlns="http://www.springframework.net">

    <object type="Spring.Objects.Factory.Config.PropertyPlaceh olderConfigurer, Spring.Core">
    <property name="ConfigSections" value="databaseSettings"/>
    </object>

    <object id="dbProvider" type="Spring.Data.Support.SqlProvider, Spring.Data">
    <property name="ConnectionString" value="Data Source=${datasource.connection.server};Initial Catalog=${datasource.connection.database};User Id=${datasource.connection.userId};Password=${data source.connection.password}"/>
    </object>

    I try to use 1.1.0 Preview 3 with the following declaration (exactly like in the example or the doc) :

    <?xml version="1.0" encoding="utf-8" ?>

    <objects xmlns="http://www.springframework.net"
    xmlns:db="http://www.springframework.net/database">

    <object type="Spring.Objects.Factory.Config.PropertyPlaceh olderConfigurer, Spring.Core">
    <property name="ConfigSections" value="databaseSettings"/>
    </object>

    <db:dbProvider id="dbProvider" provider="SqlServer-2.0" connectionString="Data Source=${datasource.connection.server};Initial Catalog=${datasource.connection.database};User Id=${datasource.connection.userId};Password=${data source.connection.password}"/>

    but I always get the error message "The 'http://www.springframework.net/database:dbProvider' element is not declared." Even Visual studio warns me about that when I open the xml file.

    To load the context I use
    IApplicationContext ctx = ContextRegistry.GetContext();

    Moreover, it would be great if the PropertyPlaceholderConfigurer could read the ConnectionStrings section in the config file.

    Last but not least, where can I find the Log4NetLoggingAroundAdvice (see here) ? I would like to play with it as a preInterceptor for the TransactionProxyFactoryObject but it is not in the 1.1-P3, not even in the nightly build.

    Thanks for your help,

    Gengis
    Last edited by Gengis; 01-03-2007 at 11:03 PM.

  2. #2
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,409

    Default

    Salut Gengis,

    Quote Originally Posted by Gengis View Post
    but I always get the error message "The 'http://www.springframework.net/database:dbProvider' element is not declared." Even Visual studio warns me about that when I open the xml file.
    Maybe you forgot to register the Database configuration parser in the main file :

    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      
      <configSections>
        <sectionGroup name="spring">
          <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
          <section name="parsers" type="Spring.Context.Support.ConfigParsersSectionHandler, Spring.Core" />
        </sectionGroup>
      </configSections>
    
      <spring>
        <context>
          <resource uri="..." />
        </context>
        <parsers>
          <parser type="Spring.Data.DatabaseConfigParser, Spring.Data" />
        </parsers>
      </spring>
    
    </configuration>

    Quote Originally Posted by Gengis View Post
    Moreover, it would be great if the PropertyPlaceholderConfigurer could read the ConnectionStrings section in the config file.
    Yep, and it seems you are not the only one asking for this.


    Quote Originally Posted by Gengis View Post
    Last but not least, where can I find the Log4NetLoggingAroundAdvice (see here) ? I would like to play with it as a preInterceptor for the TransactionProxyFactoryObject but it is not in the 1.1-P3, not even in the nightly build.
    We removed all dependencies on log4net and now depend on 'Commong.Logging', a logging abstraction library.
    You can find a CommonLoggingAroundAdvice within Spring.Calculator example.


    Bruno
    My english is as poor as my taylor is rich

  3. #3
    Join Date
    Apr 2006
    Posts
    11

    Default

    Thanks Bruno, it works.

    Now I have an error message : "Object class [Spring.Data.NHibernate.HibernateTransactionManager , Spring.Data.NHibernate] not found." Nothing serious, I am working on it (I use Spring 1.1.0-P3 and Spring.Data.NHibernate-20070102-0524).

    For the ConnectionStrings instead of databaseSettings, I process like that :
    http://forum.springframework.net/showthread.php?t=1272

    Thanks,

    Gengis

  4. #4
    Join Date
    Oct 2006
    Location
    Bergen, Norway
    Posts
    365

    Default

    Hi!

    I have a similar problem and it can be solved by putting everything in the app.config file (loaded from that context) as you already suggested above Bruno. But how can the same configuration be achieved if you do not want to use the app.config file, and you do not want to configure this from the main class.

    In my scenario the app.config file is not the best approach because the middleware server will be initialized from a com+ service component. When running as a library service the client's app.config file will be the one used, and that app.config file will be used to DI various factories, managers and service classes which is very different from those that will be injected into the middleware server and the client should not know anything about the database.

    I can, and I probably will specify the middleware server's application.config and application.manifest and point to those from the component services activation tab, but then the component must be run as a server and it is not possible to step into server initialized code, not very convenient for debugging.

    Thus I want to specify my configuration independent of app.config and independent of how the service is run (library or server). When I try to do this by almost creating a file similar to the app.config file, then I get an error message complaining that 'There is no parser registered for namespace':

    Code:
    Error registering object with name '' 
    defined in 'assembly [EFM_Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], 
    resource [EFM_Configuration.efm.config.xml]' : There is no parser registered for namespace ''
    <configuration>
      <configSections>
        <sectionGroup name="common"><section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
        </sectionGroup>
         <sectionGroup name="spring"><section name="context" type="Spring.Context.Support.ContextH...
    I interpret this error message to mean that XmlApplicationContext does not know how to read my configuration file and don't understand the configuration/configSections/sectionGroup tags.
    The only way I've currently been able to read an xml configuration file outside of the app.config file is by loading my own config file like this:

    Code:
    IApplicationContext context = new XmlApplicationContext("assembly://EFM_Configuration/EFM_Configuration/efm.config.xml");
    And then all the nodes provided in that xml file are of type object wrapped inside the objects tag:
    Code:
    <objects>
      <object ... />
    </objects>
    And when I specify the <db:dbProvider...> tag then I get the same error as described by Gengis. I really wish I could specify the parser from object's tag and thus be able to load my configuration indepedently of how the application is started.

    Currently, the efm.config.xml file looks like this, very similar to the Spring.Northwind.IntegrationTests.dll.config file:

    Code:
    <configuration>
      <configSections>
        <sectionGroup name="common">
          <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
        </sectionGroup>
        <sectionGroup name="spring">
          <section name='context' type='Spring.Context.Support.ContextHandler, Spring.Core'/>
          <section name="parsers" type="Spring.Context.Support.ConfigParsersSectionHandler, Spring.Core" />
        </sectionGroup>
        <section name="databaseSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
      </configSections>
      <common>
        <logging>
          <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
            <arg key="configType" value="EXTERNAL" />
          </factoryAdapter>
        </logging>
      </common>
      <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="hibernate.config.xml" />
        </context>
      </spring>
    
      <!-- These properties are referenced in hibernate.config.xml -->
      <databaseSettings>
        <add key="db.datasource" value="(local)" />
        <add key="db.user" value="test" />
        <add key="db.password" value="test" />
        <add key="db.database" value="test" />
      </databaseSettings>
    
      <log4net>
        <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%-5level %logger - %message%newline" />
          </layout>
        </appender>
    
        <!-- Set default logging level to DEBUG -->
        <root>
          <level value="DEBUG" />
          <appender-ref ref="ConsoleAppender" />
        </root>
    
        <!-- Set logging for Spring to INFO.  Logger names in Spring
               correspond to the namespace -->
        <!-- Note in this example, the example code uses the logging name
               Spring.Examples.MovieFinder.MovieApp -->
        <logger name="Spring">
          <level value="INFO" />
        </logger>
    
        <logger name="Spring.Data">
          <level value="INFO" />
        </logger>
    
        <logger name="NHibernate">
          <level value="INFO" />
        </logger>
    
    
      </log4net>
    </configuration>

    And the hibernate.config.xml:
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <objects xmlns="http://www.springframework.net"
             xmlns:db="http://www.springframework.net/database">
      <!-- Instansiating the EFM_IModelAssembly class-->
      <object id="ModelAssemblyRef" type="efm.model.EFM_ModelAssembly, EFM_ModelImpl" factory-method="GetInstance"/>
      <!-- Getting a reference to the Assembly method that is in the EFM_ModelAssembly class -->
      <object id="model_assembly" factory-object="ModelAssemblyRef" factory-method="GetAssembly"/>
    
      <!-- Instansiating the EFM_IModelAssembly class-->
      <object id="IModelAssemblyRef" type="efm.model.EFM_IModelAssembly, EFM_IModel" factory-method="GetInstance"/>
      <!-- Getting a reference to the Assembly method that is in the EFM_IModelAssembly class -->
      <object id="imodel_assembly" factory-object="IModelAssemblyRef" factory-method="GetAssembly"/>
    
      <!-- Creating the default context init class holding the assemblies -->
      <object id="ContextInitializerRef" type="VizCore.Viz.Core.Configuration.ElvizContextInitializer, VizCore">
        <constructor-arg name="domainModelAssembly" ref="model_assembly" />
        <constructor-arg name="idomainModelAssembly" ref="imodel_assembly" />
      </object>
    
      <!-- Database and NHibernate Configuration -->
      <db:dbProvider id="DbProviderRef" 
                       provider="SqlServer-2.0" 
                       connectionString="Data Source=${db.datasource};Database=${db.database};User ID=${db.user};Password=${db.password};Trusted_Connection=False"/>
    
      <object id="SessionFactory" type="VizCoreHibernatePersistence.viz.core.persistence.nhibernate.session.VizSessionFactoryObject, VizCoreHibernatePersistence">
        <constructor-arg name="domainModelAssembly" ref="model_assembly" />
        <property name="DbProvider" ref="DbProviderRef"/>
        <property name="HibernateProperties">
          <dictionary>
            <entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
            <entry key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect"/>
            <entry key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
          </dictionary>
        </property>
      </object>
    
      <!-- Hibernate Transaction Manager-->
      <object id="hibernateTransactionManager" type="Spring.Data.Orm.NHibernate.HibernateTransactionManager, Spring.Data.Orm.NHibernate">
        <property name="DbProvider" ref="DbProviderRef"/>
        <property name="sessionFactory" ref="SessionFactory"/>
      </object>
    
      <!-- TransactionInterceptor based on an attribute [Transaction()]-->
      <object id="transactionInterceptor" type="Spring.Transaction.Interceptor.TransactionInterceptor, Spring.Data">
        <property name="TransactionManager" ref="hibernateTransactionManager"/>
        <property name="TransactionAttributeSource">
          <object type="Spring.Transaction.Interceptor.AttributesTransactionAttributeSource, Spring.Data"/>
        </property>
      </object>
    
    
      <object id="DomainModelDAO" type="efm.persistence.nhibernate.dao.impl.DomainModelDAO, EFM_Persistence">
        <property name="SessionFactory" ref="SessionFactory"/>
      </object>
    
      <!-- Service layer setup-->
    
      <!-- Transaction declarations for business services.-->
      <object id="DefaultDomainModelManager" parent="txProxyTemplateViaAttributes" >
        <property name="Target">
          <object type="efm.managers.impl.DomainModelManager, EFM_Managers">
            <constructor-arg name="dao" ref="DomainModelDAO" />
          </object>
        </property>
      </object>
    
      <object id="DefaultManagerFacroty" type="efm.managers.factories.ManagerFactory, EFM_Managers" factory-method="GetManagerFactory">
        <constructor-arg name="contextInitializer" ref="ContextInitializerRef" />
        <property name="DomainModelManager" ref="DefaultDomainModelManager"/>
      </object>
    
    </objects>

    I hope anyone can enlighten me here,
    Steinar.

  5. #5
    Join Date
    Oct 2006
    Location
    Bergen, Norway
    Posts
    365

    Default

    Hi!

    Just an update if anyone has looked into my previous posting and at the embedded configuration files. I've found some errors and resolved them. This is the current (working) app.config containing all configurations which I want to move out into another custom configuration file, or maybe I'll just rename it application.config and reference it from the component's activation tab, we will see.

    Code:
    <configuration>
      <configSections>
        <sectionGroup name="spring">
          <section name="parsers" type="Spring.Context.Support.ConfigParsersSectionHandler, Spring.Core" />
          <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
          <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
        </sectionGroup>
    
        <section name="databaseSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
      </configSections>
    
      <!-- These properties are referenced in Dao.xml -->
      <databaseSettings>
        <add key="db.datasource" value="(local)" />
        <add key="db.user" value="test" />
        <add key="db.password" value="test" />
        <add key="db.database" value="test" />
      </databaseSettings>
    	
      <spring>
        <parsers>
          <parser type="Spring.Data.DatabaseConfigParser, Spring.Data" />
        </parsers>
    
        <context>
          <!-- using section in App.config for IOC of default manager factory-->
          <resource uri="config://spring/objects"/>
        </context>
    
        <objects xmlns="http://www.springframework.net"
    		 xmlns:db="http://www.springframework.net/database">
          <description>IoC of managers into the main application entry.</description>
          
          <!-- Instansiating the EFM_ModelAssembly class-->
          <object id="ModelAssemblyRef" type="efm.model.EFM_ModelAssembly, EFM_ModelImpl" 
            factory-method="GetInstance"/>
          
          <!-- Getting a reference to the Assembly method that is in the EFM_ModelAssembly class -->
          <object id="model_assembly" factory-object="ModelAssemblyRef" 
            factory-method="GetAssembly"/>
    
          <!-- Instansiating the EFM_IModelAssembly class-->
          <object id="IModelAssemblyRef" type="efm.model.EFM_IModelAssembly, EFM_IModel" 
            factory-method="GetInstance"/>
          
          <!-- Getting a reference to the Assembly method that is in the EFM_IModelAssembly class -->
          <object id="imodel_assembly" factory-object="IModelAssemblyRef" 
            factory-method="GetAssembly"/>
    
          <!-- Creating the default context init class holding the assemblies -->
          <object id="ContextInitializerRef" type="VizCore.Viz.Core.Configuration.ElvizContextInitializer, VizCore">
            <constructor-arg name="domainModelAssembly" ref="model_assembly" />
            <constructor-arg name="idomainModelAssembly" ref="imodel_assembly" />
          </object>
    
          <!-- Database and NHibernate Configuration -->
          <db:dbProvider id="DbProviderRef" provider="SqlServer-2.0" 
            connectionString= "Data Source=${db.datasource};Database=${db.database};User ID=${db.user};Password=${db.password};Trusted_Connection=False"/>
    
          <object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12">
            <property name="DbProvider" ref="DbProviderRef"/>
    	<property name="MappingAssemblies">
    	  <list>
    	    <value>EFM_ModelImpl</value>
    	  </list>
            </property>
    	<property name="HibernateProperties">
    	  <dictionary>
    	    <entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
    	    <entry key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect"/>
    	    <entry key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
    	  </dictionary>
            </property>
          </object>
    
          <!-- Hibernate Transaction Manager-->
          <object id="hibernateTransactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate12">
            <property name="DbProvider" ref="DbProviderRef"/>
    	<property name="sessionFactory" ref="SessionFactory"/>
          </object>
    
          <!-- TransactionInterceptor based on an attribute [Transaction()]-->
          <object id="transactionInterceptor" type="Spring.Transaction.Interceptor.TransactionInterceptor, Spring.Data">
            <property name="TransactionManager" ref="hibernateTransactionManager"/>
    	<property name="TransactionAttributeSource">
    	  <object type="Spring.Transaction.Interceptor.AttributesTransactionAttributeSource, Spring.Data"/>
    	</property>
          </object>
    
          <!-- Advisors -->
          <object id="log4NetLoggingAroundAdvice" type="Spring.Aop.Support.AttributeMatchMethodPointcutAdvisor, Spring.Aop">
            <property name="advice">
    	  <object type="VizCore.viz.core.aop.advice.Log4NetLoggingAroundAdvice" />
    	</property>
    	<property name="attribute" value="VizCore.viz.core.aop.attribute.Log4NetLoggingAroundAttribute"/>
          </object>
    
          <!-- Transactional Proxy for Services using the ProxyFactoryObject -->
          <object id="txProxyTemplateViaAttributes" abstract="true" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
            <property name="InterceptorNames">
    	  <list>
    	    <value>log4NetLoggingAroundAdvice</value>
    	  </list>
            </property>
          </object>
    
          <!-- setup UserDAO with NHibernate support by adding the SessionFactory -->
          <object id="UserDAO" type="efm.persistence.nhibernate.dao.impl.UserDAO, EFM_Persistence">
            <property name="SessionFactory" ref="SessionFactory"/>
          </object>
    
          <object id="DomainModelDAO" type="efm.persistence.nhibernate.dao.impl.DomainModelDAO, EFM_Persistence">
            <property name="SessionFactory" ref="SessionFactory"/>
          </object>
    
          <object id="ContentDAO" type="efm.persistence.nhibernate.dao.impl.ContentDAO, EFM_Persistence">
            <property name="SessionFactory" ref="SessionFactory"/>
          </object>
    
          <!-- Service layer setup-->
          <!-- Transaction declarations for business services.-->
          <object id="DefaultUserManager" parent="txProxyTemplateViaAttributes" >
            <property name="Target">
    	  <object type="efm.managers.impl.UserManager, EFM_Managers">
    	    <constructor-arg name="dao" ref="UserDAO" />
    	  </object>
    	</property>
          </object>
    
          <object id="DefaultDomainModelManager" parent="txProxyTemplateViaAttributes" >
            <property name="Target">
    	  <object type="efm.managers.impl.DomainModelManager, EFM_Managers">
    	    <constructor-arg name="dao" ref="DomainModelDAO" />
    	  </object>
            </property>
          </object>
    
          <object id="DefaultContentManager" parent="txProxyTemplateViaAttributes" >
            <property name="Target">
    	  <object type="efm.managers.impl.ContentManager, EFM_Managers">
    	    <constructor-arg name="dao" ref="ContentDAO" />
    	  </object>
    	</property>
          </object>
    
          <object id="DefaultCurveGenerationManager" parent="txProxyTemplateViaAttributes" >
    	<property name="Target">
              <object type="efm.managers.impl.CurveGenerationManager, EFM_Managers" />
    	</property>
          </object>
    
          <object id="DefaultManagerFactory" type="efm.managers.factories.ManagerFactory, EFM_Managers" factory-method="GetManagerFactory">
            <constructor-arg name="contextInitializer" ref="ContextInitializerRef" />
    	  <property name="UserManager" ref="DefaultUserManager"/>
    	  <property name="DomainModelManager" ref="DefaultDomainModelManager"/>
    	  <property name="ContentManager" ref="DefaultContentManager"/>
    	  <property name="CurveGenerationManager" ref="DefaultCurveGenerationManager"/>
          </object>
    
          <object id="DefaultDomainModelFactory" type="core.factories.DomainModelFactory, EFM_Factories" factory-method="GetInstance">
            <constructor-arg name="domainModelAssembly" ref="model_assembly" />
          </object>  
        </objects>
      </spring>
    
      <!-- This section contains the log4net configuration settings -->
      <log4net>
        <!-- Define an output appender (where the logs can go) -->
        <appender name="LogFileAppender" type="log4net.Appender.FileAppender, log4net">
          <param name="File" value="log.txt"/>
          <param name="AppendToFile" value="false"/>
          <layout type="log4net.Layout.PatternLayout, log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n"/>
          </layout>
        </appender>
    
        <!-- Setup the root category, set the default priority level and add the appender(s) (where the logs will go) -->
        <root>
          <priority value="DEBUG"/>
          <appender-ref ref="LogFileAppender"/>
        </root>
    
        <!-- Specify the level for some specific namespaces -->
        <!-- Level can be : ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF -->
        <!--logger name="NHibernate">
          <level value="INFO"/>
        </logger-->
    
        <!-- Set logging for Spring to INFO.  Logger names in Spring
               correspond to the namespace -->
        <!--logger name="Spring">
          <level value="INFO"/>
        </logger-->
    
      </log4net>
    
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="ICSharpCode.SharpZipLib" publicKeyToken="1B03E6ACF1164F73" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-0.84.0.0" newVersion="0.84.0.0"/>
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    If anyone knows how to create custom configuration files that can replace the app.config file then I'm very interested.

    Thanks,
    Steinar.

  6. #6
    Mark Pollack is offline Spring.NET Co-Lead Spring TeamSpring User
    Join Date
    Sep 2004
    Location
    New York, NY
    Posts
    1,683

    Default

    Hi,

    You can specify to load the context from locations other than /config/object within app.config through the use of other resource uri's. For example, from Sec 4.2 in the docs.

    Code:
    <spring>
      <context>
        <resource uri="file://objects.xml"/>
        <resource uri="assembly://MyAssembly/MyProject/objects-dal-layer.xml"/>
      </context>
    </spring>
    In this case object-dal-layer.xml is an embedded assembly resource. The sample 'Calculator' project and 'SpringAir' project show examples of separating object definitions into different files, i.e. one for aspects, etc. In this case you will still need to register custom parser within app.config. If you are using the custom 'db' schema, that will need to be declared within each top level <objects... > declaration

    Let me know if I'm on the right track here in terms of what you are trying to do.

    Cheers,
    Mark

  7. #7
    Join Date
    Nov 2006
    Posts
    7

    Default Need register the db parser outside of app.config

    Hi, steinard,

    Just want to check whether you made that work or not? I have the same issue as you. Can not access the app.config file and loading all objects in seperate xml files. However, can not register the db parse as normally in app.config's configsections.

    Appreciate it if anybody can point to the right direction!!!

    Thanks

    Leon

  8. #8
    Join Date
    Sep 2004
    Location
    Belgrade, Serbia
    Posts
    613

    Default

    I might be pointing out the obvious, but you can also do programmatically everything you can do using .NET configuration -- register custom configuration parsers, type aliases, type converters, etc.

    1. To register configuration parser, use one of the XmlParserRegistry.RegisterParser() overloads;

    2. For type aliases, use one of TypeRegistry.RegisterType() overloads;

    3. For custom type converters, use one of TypeConverterRegistry.RegisterConverter() methods

    4. For custom resource implementations use one of ResourceHandlerRegistry.RegisterResourceHandler() methods.

    That's effectively what various configuration section handlers do for you, but in some cases it makes a lot more sense to do it directly, by making appropriate API calls. This is especially true when you need to load the context into separate and somewhat "exotic" environments, such as COM+ container, as it eliminates dependency on .NET configuration files.

    Bootstraping context directly using XmlApplicationContext constructor also makes perfect sense in such an environment, but you need to make sure all custom parsers are registered before you try to load the context. Custom config parsers that are built into Spring.Core will be automatically registered, but you will have to register parsers that exist within other assemblies, such as Spring.Data or Spring.Services, manually.

    HTH,

    Aleks

  9. #9
    Join Date
    Oct 2006
    Location
    Bergen, Norway
    Posts
    365

    Default

    Hi!

    I had this problem a while back when I was fighting the com+ way of reading in a custom configuration, but I gave up, simply using the application.config and application.manifest files that enterprise services expects. When it comes to remoting scenarios I've (lately) had no problems putting parts of my configuration in a seperate embedded resource file.

    If you look at the calculator example you will see pretty good examples of embedded configuration files.

    Hope you solve your problem soon,
    Steinar.

  10. #10
    Join Date
    Nov 2006
    Location
    Hyderabad, India
    Posts
    13

    Default How to configure Spring in a powershell script

    but I gave up, simply using the application.config and application.manifest files that enterprise services expects
    I know that this is an old thread. But I felt that the note on which the thread closed--we cannot avoid using App.Config for configuring Spring--is not true, any longer. For a solution, please refer to Chapter 35 Transactions Quickstart (specifically 35.4) in the documentation for 1.2.0 M1 release.

    Based on the Quickstart this is how we configured Spring in a powershell script:

    Code:
      # register DB namespace parser
      $dbNsParserType = $(new-object Spring.Data.Config.DatabaseNamespaceParser).GetType()
      [Spring.Objects.Factory.Xml.NamespaceParserRegistry]::RegisterParser( $dbNsParserType );
      # register Transaction namespace parser
      $txNsParserType = $(new-object Spring.Transaction.Config.TxNamespaceParser).GetType()
      [Spring.Objects.Factory.Xml.NamespaceParserRegistry]::RegisterParser( $txNsParserType );
    
      # instantiate the context from the external config file
      $ctx = new-object Spring.Context.Support.XmlApplicationContext "file://SpringConfig.xml"
     
      # Register the context
      [Spring.Context.Support.ContextRegistry]::RegisterContext( $ctx )
    The alternative would have been to copy the config into
    C:\WINDOWS\system32\windowspowershell\v1.0\powersh ell.exe.config.
    And we will have to do this on every machine on which we want to execute the script!
    Last edited by sreenivask; 10-07-2008 at 02:40 AM. Reason: Ambiguous title

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •