Announcement Announcement Module
Collapse
No announcement yet.
Configuring in a standalone app Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring in a standalone app

    Hi

    I'm trying to discover how to configure my Spring - Hibernate desktop app but every doc I found is web container oriented.

    I've a jar file wrapping all my classes and config files as follows:

    Code:
     META-INF/
     META-INF/MANIFEST.MF
     applicationContext-dao.xml
     applicationContext-service.xml
     applicationContext.xml
     Clientes.hbm.xml
     Control.hbm.xml
     hibernate.cfg.xml
     Subdelegacion.hbm.xml
     Telefonos.hbm.xml
     com/
     com/jl/
     com/jl/..... (all my classes)
    this is my application.jar and outside it I've a log4j.xml and a properties file.

    My properties file is

    Code:
    hibernate.connection.driver_class = net.sourceforge.jtds.jdbc.Driver
    hibernate.connection.url = "jdbc:jtds:sqlserver://localhost:4811/vvvv"
    hibernate.connection.username = sa
    hibernate.connection.password = xxxx
    hibernate.default_schema = dbo

    And I expect thos values be replaced in applicationConext.xml file (inside my jar)

    Code:
    <beans>
    	<bean id="dataSource"
    		class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName" value="${hibernate.connection.driver_class}" />
    		<property name="url" value="${hibernate.connection.url}" />
    		<property name="username" value="${hibernate.connection.username}" />
    		<property name="password" value="${hibernate.connection.password}" /> 
        </bean>
        
    </beans>

    So, in my code I did:

    Code:
    try {
            	try {
            	InputStream is = new FileInputStream("aplicaciona.properties");	
            	Properties p = new Properties();
            	p.load(is);
            	
            	System.setProperties(p);
            	        
    
            	String[] paths = {"applicationContext-dao.xml",
            		"applicationContext.xml",
            		"applicationContext-service.xml"};
    
            	ctx = new ClassPathXmlApplicationContext(paths);
            	
            } catch (FileNotFoundException e) {
            	logger.error("Could not find properties file. " + e.getMessage());
            	e.printStackTrace();
            } catch (IOException e) {
            	logger.error("Could not find properties file. " + e.getMessage());
            	e.printStackTrace();        	
            } catch (Exception e) {
            	logger.error(e.getMessage());
            	e.printStackTrace();        	        	
            }

    But when I run my application I got the exception:

    Code:
    0    [main] INFO  com.jl.xxx.AplicacionA  - starting app.
    0    [main] INFO  com.jl.xxx.AplicacionA  - starting app.
    Exception in thread "main" java.lang.ExceptionInInitializerError
            at org.springframework.core.CollectionFactory.<clinit>(CollectionFactory
    .java:60)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.
    getBeansOfType(DefaultListableBeanFactory.java:199)
            at org.springframework.context.support.AbstractApplicationContext.getBea
    nsOfType(AbstractApplicationContext.java:612)
            at org.springframework.context.support.AbstractApplicationContext.regist
    erBeanPostProcessors(AbstractApplicationContext.java:403)
            at org.springframework.context.support.AbstractApplicationContext.refres
    h(AbstractApplicationContext.java:303)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<i
    nit>(ClassPathXmlApplicationContext.java:81)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<i
    nit>(ClassPathXmlApplicationContext.java:66)

    Raised at ctx = new ClassPathXmlApplicationContext(paths); line.

    Why this error ? Is this a good way to init my app ?

    Thanks in advance

    C

  • #2
    Try
    Code:
    String[] paths = {"classpath:applicationContext-dao.xml",
            		"classpath:applicationContext.xml",
            		"classpath:applicationContext-service.xml"};
    or

    Code:
    String[] paths = {"classpath*:applicationContext-dao.xml",
            		"classpath*:applicationContext.xml",
            		"classpath*:applicationContext-service.xml"};

    Of course the containng jar must be in the classpath.

    Comment


    • #3
      Originally posted by kantorn View Post
      Try
      Code:
      String[] paths = {"classpath:applicationContext-dao.xml",
              		"classpath:applicationContext.xml",
              		"classpath:applicationContext-service.xml"};
      or

      Code:
      String[] paths = {"classpath*:applicationContext-dao.xml",
              		"classpath*:applicationContext.xml",
              		"classpath*:applicationContext-service.xml"};

      Of course the containng jar must be in the classpath.

      Hi

      thanks for your reply.

      I've tried both methods with the same result: the problem is still there.

      I'm launching as folows:

      Code:
      java -jar aplicaciona.jar
      And the manifest inside the jar is:

      Code:
      Main-Class: com.jl.segex.AplicacionA
      Class-Path: ./ ./lib/aopalliance-1.0.jar 
       ./lib/asm-1.5.3.jar 
       ./lib/asm-attrs-1.5.3.jar ./lib/backport-util-concurrent-2.0_01_pd.jar 
       ./lib/cglib-2.1_3.jar ./lib/commons-beanutils-1.7.0.jar 
       ./lib/commons-collections-2.1.1.jar ./lib/commons-dbcp-1.2.1.jar 
       ./lib/commons-discovery-0.4.jar
       ./lib/commons-lang-2.1.jar ./lib/commons-logging-1.0.3.jar 
       ./lib/commons-pool-1.2.jar ./lib/dom4j-1.6.1.jar ./lib/ehcache-1.2.3.jar 
       ./lib/hibernate-3.2.2.ga.jar ./lib/jta-1.0.1B.jar ./lib/jtds-1.2.jar 
       ./lib/log4j-1.2.14.jar ./lib/mx4j-3.0.1.jar ./lib/poi-2.5.1-final-20040804.jar 
       ./lib/qdox-1.5.jar ./lib/spring-1.2.4.jar ./lib/spring-aop-2.0.2.jar 
       ./lib/spring-beans-2.0.2.jar ./lib/spring-context-2.0.2.jar 
       ./lib/spring-core-2.0.2.jar ./lib/spring-dao-2.0.2.jar 
       ./lib/spring-hibernate3-2.0.2.jar ./lib/spring-jdbc-2.0.2.jar 
       ./lib/spring-remoting-2.0.2.jar ./lib/spring-support-2.0.2.jar 
       ./lib/spring-web-2.0.2.jar ./lib/stax-api-1.0.jar ./lib/xbean-spring-2.1.jar 
       ./lib/xercesImpl-2.0.2.jar
       ./lib/xml-apis-1.0.b2.jar ./lib/xmlParserAPIs-2.6.2.jar



      So I assume the first ./ place my jar inside classpath.

      nevertheless, I've tried with:

      java -classpath ./ -jar aplicaciona.jar

      Without success...

      Any idea ?

      Thanks in advance

      C

      Comment


      • #4
        Originally posted by cacho View Post
        So I assume the first ./ place my jar inside classpath.
        Your jar is automatically in the classpath when you use "-jar".

        Originally posted by cacho View Post
        java -classpath ./ -jar aplicaciona.jar
        -classpath and -jar do not work together.
        You would have to use -classpath alone (in that case including you jarfile) and specify the main-class explicitly. But I do not think that this is the problem here.

        Could you post again the stacktrace in complete form? There is something about ExceptionInInitializer but I suspect there should be a nested exception as well.

        Regards,
        Andreas

        Comment


        • #5
          Originally posted by Andreas Senft View Post
          Your jar is automatically in the classpath when you use "-jar".



          -classpath and -jar do not work together.
          You would have to use -classpath alone (in that case including you jarfile) and specify the main-class explicitly. But I do not think that this is the problem here.

          Could you post again the stacktrace in complete form? There is something about ExceptionInInitializer but I suspect there should be a nested exception as well.

          Regards,
          Andreas
          Thanks for your reply.

          The complete exceptio follows:

          Code:
          0    [main] INFO  com.jl.segex.AplicacionA  - starting app.
          0    [main] INFO  com.jl.segex.AplicacionA  - starting app.
          Exception in thread "main" java.lang.ExceptionInInitializerError
                  at org.springframework.core.CollectionFactory.<clinit>(CollectionFactory
          .java:60)
                  at org.springframework.beans.factory.support.DefaultListableBeanFactory.
          getBeansOfType(DefaultListableBeanFactory.java:199)
                  at org.springframework.context.support.AbstractApplicationContext.getBea
          nsOfType(AbstractApplicationContext.java:612)
                  at org.springframework.context.support.AbstractApplicationContext.regist
          erBeanPostProcessors(AbstractApplicationContext.java:403)
                  at org.springframework.context.support.AbstractApplicationContext.refres
          h(AbstractApplicationContext.java:303)
                  at org.springframework.context.support.ClassPathXmlApplicationContext.<i
          nit>(ClassPathXmlApplicationContext.java:81)
                  at org.springframework.context.support.ClassPathXmlApplicationContext.<i
          nit>(ClassPathXmlApplicationContext.java:66)
                  at com.jl.xxx.AplicacionA.<init>(AplicacionA.java:65)
                  at com.jl.xxx.AplicacionA.main(AplicacionA.java:183)
          Caused by: java.lang.NullPointerException
                  at org.springframework.core.JdkVersion.<clinit>(JdkVersion.java:41)
                  ... 9 more

          Thanks in advance

          C

          Comment


          • #6
            What version of Spring are you running?

            Comment


            • #7
              Hi

              I'm using 2.0.2.

              I've solved my Poltergeist mistery but have a new one...

              After some debug I discovered the error was in this line:

              Code:
              p.load(is);
                      	
              System.setProperties(p);
              Where p comes with null lines.

              I've changed this with:

              Code:
              InputStream is = new FileInputStream("aplicaciona.properties");
                      	Properties p = new Properties();
                      	p.load(is);
              
                          System.setProperty("hibernate.connection.driver_class",
                                  p.getProperty("hibernate.connection.driver_class"));
                          System.setProperty("hibernate.connection.url",
                                  p.getProperty("hibernate.connection.url"));
                          System.setProperty("hibernate.connection.username",
                                  p.getProperty("hibernate.connection.username"));
                          System.setProperty("hibernate.connection.password",
                                  p.getProperty("hibernate.connection.password"));
                          System.setProperty("hibernate.default_schema",
                                  p.getProperty("hibernate.default_schema"));
              
              
                          String[] paths = {"./applicationContext-dao.xml",
                      		"./applicationContext.xml",
                      		"./applicationContext-service.xml"};
              
                      	ctx = new FileSystemXmlApplicationContext(paths);
              But the error now is:

              Code:
              0    [main] INFO  com.jl.xxx.AplicacionA  - starting app.
              0    [main] INFO  com.jl.xxx.AplicacionA  - starting app.
              875  [main] ERROR org.hibernate.util.JDBCExceptionReporter  - Cannot load JDBC d
              river class '${hibernate.connection.driver_class}'
              1188 [main] ERROR org.hibernate.util.JDBCExceptionReporter  - Cannot load JDBC d
              river class '${hibernate.connection.driver_class}'
              1188 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate  - could not get datab
              ase metadata
              org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${hib
              ernate.connection.driver_class}'
                      at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou
              rce.java:766)
                      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource
              .java:540)
                      at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.
              getConnection(LocalDataSourceConnectionProvider.java:80)
                      at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper
              .prepare(SuppliedConnectionProviderConnectionHelper.java:27)
                      at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127
              )
                      at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:
              314)
                      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
              a:1294)
                      at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSession
              Factory(LocalSessionFactoryBean.java:777)
                      at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPrope
              rtiesSet(LocalSessionFactoryBean.java:703)
                      at org.springframework.beans.factory.support.AbstractAutowireCapableBean
              Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1058)
                      at org.springframework.beans.factory.support.AbstractAutowireCapableBean
              Factory.createBean(AbstractAutowireCapableBeanFactory.java:363)
                      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
              (AbstractBeanFactory.java:226)
                      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
              (AbstractBeanFactory.java:147)
                      at org.springframework.beans.factory.support.DefaultListableBeanFactory.
              preInstantiateSingletons(DefaultListableBeanFactory.java:269)
                      at org.springframework.context.support.AbstractApplicationContext.refres
              h(AbstractApplicationContext.java:318)
                      at org.springframework.context.support.FileSystemXmlApplicationContext.<
              init>(FileSystemXmlApplicationContext.java:83)
                      at org.springframework.context.support.FileSystemXmlApplicationContext.<
              init>(FileSystemXmlApplicationContext.java:68)
                      at com.jl.xxx.AplicacionA.<init>(AplicacionA.java:68)
                      at com.jl.xxx.AplicacionA.main(AplicacionA.java:186)
              Caused by: java.lang.ClassNotFoundException: ${hibernate.connection.driver_class
              }
                      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
                      at java.security.AccessController.doPrivileged(Native Method)
                      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
                      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
                      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
                      at java.lang.Class.forName0(Native Method)
                      at java.lang.Class.forName(Class.java:169)
                      at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou
              rce.java:760)
                      ... 18 more
              1203 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate  - could not complete
              schema update
              org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${hib
              ernate.connection.driver_class}'
                      at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou
              rce.java:766)
                      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource
              .java:540)
                      at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.
              getConnection(LocalDataSourceConnectionProvider.java:80)
                      at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper
              .prepare(SuppliedConnectionProviderConnectionHelper.java:27)
                      at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127
              )
                      at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:
              314)
                      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
              a:1294)
                      at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSession
              Factory(LocalSessionFactoryBean.java:777)
                      at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPrope
              rtiesSet(LocalSessionFactoryBean.java:703)
                      at org.springframework.beans.factory.support.AbstractAutowireCapableBean
              Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1058)
                      at org.springframework.beans.factory.support.AbstractAutowireCapableBean
              Factory.createBean(AbstractAutowireCapableBeanFactory.java:363)
                      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
              (AbstractBeanFactory.java:226)
                      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
              (AbstractBeanFactory.java:147)
                      at org.springframework.beans.factory.support.DefaultListableBeanFactory.
              preInstantiateSingletons(DefaultListableBeanFactory.java:269)
                      at org.springframework.context.support.AbstractApplicationContext.refres
              h(AbstractApplicationContext.java:318)
                      at org.springframework.context.support.FileSystemXmlApplicationContext.<
              init>(FileSystemXmlApplicationContext.java:83)
                      at org.springframework.context.support.FileSystemXmlApplicationContext.<
              init>(FileSystemXmlApplicationContext.java:68)
                      at com.jl.xxx.AplicacionA.<init>(AplicacionA.java:68)
                      at com.jl.xxx.AplicacionA.main(AplicacionA.java:186)
              Caused by: java.lang.ClassNotFoundException: ${hibernate.connection.driver_class
              }
                      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
                      at java.security.AccessController.doPrivileged(Native Method)
                      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
                      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
                      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
                      at java.lang.Class.forName0(Native Method)
                      at java.lang.Class.forName(Class.java:169)
                      at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou
              rce.java:760)
                      ... 18 more

              So, my question now is how could I do what I want ?: Load some properties from a properties file and let Spring to automatically use those values instead of ${some.properti.value} in my Hibernate config files...


              Thanks in advance

              C

              Comment


              • #8
                Have you got a PropertyPlaceholderConfigurer bean in the configuration? I would presume that the value isn't getting replaced. Is it possible to see the configuration file that contains the dataSource?

                Comment


                • #9
                  Originally posted by karldmoore View Post
                  Have you got a PropertyPlaceholderConfigurer bean in the configuration? I would presume that the value isn't getting replaced. Is it possible to see the configuration file that contains the dataSource?
                  Ouch, I guess I've not this. How should I added ?

                  My datasource is configured as follows

                  applicationcontext.xml
                  Code:
                  <beans>
                  	<bean id="dataSource"
                  		class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
                  		<property name="driverClassName" value="${hibernate.connection.driver_class}" />
                  		<property name="url" value="${hibernate.connection.url}" />
                  		<property name="username" value="${hibernate.connection.username}" />
                  		<property name="password" value="${hibernate.connection.password}" /> 
                      </bean>
                      
                  </beans>
                  applicationcontext-dao.xml
                  Code:
                   <bean id="sessionFactory"
                            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                          <property name="dataSource">
                              <ref bean="dataSource"/>
                          </property>
                          <property name="configLocation">
                              <value>./hibernate.cfg.xml</value>
                          </property>
                          <!--property name="configurationClass">
                              <value>org.hibernate.cfg.AnnotationConfiguration</value>
                          </property -->
                          <property name="hibernateProperties">
                              <props>
                                  <prop key="hibernate.dialect">
                                      org.hibernate.dialect.SQLServerDialect
                                  </prop>
                                  <prop key="hibernate.hbm2ddl.auto">update</prop>
                                  <prop key="hibernate.default_schema">${hibernate.default_schema}</prop>
                                  <prop key="hibernate.show_sql">true</prop>                
                              </props>
                          </property>
                      </bean>
                  Thanks in advance

                  C

                  Comment


                  • #10
                    I guess that explains it . If you are just checking SystemProperties something like this should be ok.
                    Code:
                     	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                    		<property name="systemPropertiesMode" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
                    	</bean>
                    http://www.springframework.org/docs/...onfigurer.html

                    Comment


                    • #11
                      Thank you !!!

                      Comment


                      • #12
                        Not a problem, I'm glad to help. Did that fix it then?

                        Comment


                        • #13
                          Originally posted by karldmoore View Post
                          Not a problem, I'm glad to help. Did that fix it then?

                          Hi, well, this start to be a nightmare...

                          I did in my

                          Code:
                          <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                          		<property name="systemPropertiesMode" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
                          	</bean>

                          But when I run my app I got

                          Code:
                          0    [main] INFO  com.jl.xxx.AplicacionA  - starting app.
                          0    [main] INFO  com.jl.xxx.AplicacionA  - starting app.
                          375  [main] ERROR com.jl.xxx.AplicacionA  - Error creating bean with name 'pro
                          pertyConfigurer' defined in file [C:\work\vigixxx\vigixxx\AplicacionA\trunk\
                          target\.\applicationContext.xml]: Initialization of bean failed; nested exceptio
                          n is org.springframework.beans.TypeMismatchException: Failed to convert property
                           value of type [java.lang.String] to required type [int] for property 'systemPro
                          pertiesMode'; nested exception is java.lang.NumberFormatException: For input str
                          ing: "SYSTEM_PROPERTIES_MODE_OVERRIDE"
                          375  [main] ERROR com.jl.xxx.AplicacionA  - Error creating bean with name 'pro
                          pertyConfigurer' defined in file [C:\work\vigixxx\vigixxx\AplicacionA\trunk\
                          target\.\applicationContext.xml]: Initialization of bean failed; nested exceptio
                          n is org.springframework.beans.TypeMismatchException: Failed to convert property
                           value of type [java.lang.String] to required type [int] for property 'systemPro
                          pertiesMode'; nested exception is java.lang.NumberFormatException: For input str
                          ing: "SYSTEM_PROPERTIES_MODE_OVERRIDE"
                          org.springframework.beans.factory.BeanCreationException: Error creating bean wit
                          h name 'propertyConfigurer' defined in file [C:\work\vigixxx\vigixxx\Aplicac
                          ionA\trunk\target\.\applicationContext.xml]: Initialization of bean failed; nest
                          ed exception is org.springframework.beans.TypeMismatchException: Failed to conve
                          rt property value of type [java.lang.String] to required type [int] for property
                           'systemPropertiesMode'; nested exception is java.lang.NumberFormatException: Fo
                          r input string: "SYSTEM_PROPERTIES_MODE_OVERRIDE"
                          Caused by: org.springframework.beans.TypeMismatchException: Failed to convert pr
                          operty value of type [java.lang.String] to required type [int] for property 'sys
                          temPropertiesMode'; nested exception is java.lang.NumberFormatException: For inp
                          ut string: "SYSTEM_PROPERTIES_MODE_OVERRIDE"
                          Caused by: java.lang.NumberFormatException: For input string: "SYSTEM_PROPERTIES
                          _MODE_OVERRIDE"
                                  at java.lang.NumberFormatException.forInputString(NumberFormatException.
                          java:48)
                                  at java.lang.Integer.parseInt(Integer.java:447)
                                  at java.lang.Integer.valueOf(Integer.java:526)
                                  at java.lang.Integer.decode(Integer.java:918)
                                  at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:146
                          )
                                  at org.springframework.beans.propertyeditors.CustomNumberEditor.setAsTex
                          t(CustomNumberEditor.java:114)
                                  at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(Ty
                          peConverterDelegate.java:320)
                                  at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeCo
                          nverterDelegate.java:304)
                                  at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(Ty
                          peConverterDelegate.java:192)
                                  at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(Ty
                          peConverterDelegate.java:138)
                                  at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrap
                          perImpl.java:380)
                                  at org.springframework.beans.factory.support.AbstractAutowireCapableBean
                          Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1085)
                                  at org.springframework.beans.factory.support.AbstractAutowireCapableBean
                          Factory.populateBean(AbstractAutowireCapableBeanFactory.java:835)
                                  at org.springframework.beans.factory.support.AbstractAutowireCapableBean
                          Factory.createBean(AbstractAutowireCapableBeanFactory.java:423)
                                  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
                          ject(AbstractBeanFactory.java:251)
                                  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
                          y.getSingleton(DefaultSingletonBeanRegistry.java:144)
                                  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
                          (AbstractBeanFactory.java:248)
                                  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
                          (AbstractBeanFactory.java:160)
                                  at org.springframework.context.support.AbstractApplicationContext.invoke
                          BeanFactoryPostProcessors(AbstractApplicationContext.java:426)
                                  at org.springframework.context.support.AbstractApplicationContext.refres
                          h(AbstractApplicationContext.java:342)
                                  at org.springframework.context.support.FileSystemXmlApplicationContext.<
                          init>(FileSystemXmlApplicationContext.java:93)
                                  at org.springframework.context.support.FileSystemXmlApplicationContext.<
                          init>(FileSystemXmlApplicationContext.java:77)
                                  at com.jl.xxx.AplicacionA.<init>(AplicacionA.java:68)
                                  at com.jl.xxx.AplicacionA.main(AplicacionA.java:189)

                          Why ? I really don't know because I imagine SYSTEM_PROPERTIES_MODE_OVERRIDE is a constant inside a Spring jar placed in my classpath..


                          So I decided to change the symbol by the real int value:

                          Code:
                          <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                          		<property name="systemPropertiesMode" value="2"/>
                          	</bean>

                          But then I got:

                          Code:
                          0    [main] INFO  com.jl.xxx.AplicacionA  - starting app.
                          0    [main] INFO  com.jl.xxx.AplicacionA  - starting app.
                          1593 [main] ERROR org.hibernate.util.JDBCExceptionReporter  - Cannot create JDBC
                           driver of class 'net.sourceforge.jtds.jdbc.Driver' for connect URL '"jdbc:jtds:
                          sqlserver://localhost:4811/xxx"'
                          2437 [main] ERROR org.hibernate.util.JDBCExceptionReporter  - Cannot create JDBC
                           driver of class 'net.sourceforge.jtds.jdbc.Driver' for connect URL '"jdbc:jtds:
                          sqlserver://localhost:4811/xxx"'
                          2453 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate  - could not get datab
                          ase metadata
                          org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '
                          net.sourceforge.jtds.jdbc.Driver' for connect URL '"jdbc:jtds:sqlserver://localh
                          ost:4811/xxx"'
                                  at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou
                          rce.java:780)
                                  at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource
                          .java:540)
                                  at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.
                          getConnection(LocalDataSourceConnectionProvider.java:81)
                                  at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper
                          .prepare(SuppliedConnectionProviderConnectionHelper.java:27)
                                  at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127
                          )
                                  at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:
                          314)
                                  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
                          a:1294)
                                  at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSession
                          Factory(LocalSessionFactoryBean.java:805)
                                  at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessi
                          onFactory(LocalSessionFactoryBean.java:745)
                                  at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPr
                          opertiesSet(AbstractSessionFactoryBean.java:134)
                                  at org.springframework.beans.factory.support.AbstractAutowireCapableBean
                          Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1175)
                                  at org.springframework.beans.factory.support.AbstractAutowireCapableBean
                          Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1145)
                                  at org.springframework.beans.factory.support.AbstractAutowireCapableBean
                          Factory.createBean(AbstractAutowireCapableBeanFactory.java:427)
                                  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
                          ject(AbstractBeanFactory.java:251)
                                  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
                          y.getSingleton(DefaultSingletonBeanRegistry.java:144)
                                  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
                          (AbstractBeanFactory.java:248)
                                  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
                          (AbstractBeanFactory.java:160)
                                  at org.springframework.beans.factory.support.DefaultListableBeanFactory.
                          preInstantiateSingletons(DefaultListableBeanFactory.java:276)
                                  at org.springframework.context.support.AbstractApplicationContext.refres
                          h(AbstractApplicationContext.java:360)
                                  at org.springframework.context.support.FileSystemXmlApplicationContext.<
                          init>(FileSystemXmlApplicationContext.java:93)
                                  at org.springframework.context.support.FileSystemXmlApplicationContext.<
                          init>(FileSystemXmlApplicationContext.java:77)
                                  at com.jl.xxx.AplicacionA.<init>(AplicacionA.java:68)
                                  at com.jl.xxx.AplicacionA.main(AplicacionA.java:189)
                          Caused by: java.sql.SQLException: No suitable driver
                                  at java.sql.DriverManager.getDriver(DriverManager.java:264)
                                  at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou
                          rce.java:773)

                          The driver IS in my classpath and the classpath is well defined in my jar so...I don't know what to do. Its so frustrant !!!

                          The worst thing is that this exception could not be captured by my app so the program try to follow running wityhout a DB connection...

                          Any clue welcome...


                          Thanks in advance

                          C

                          Comment


                          • #14
                            Apologies, it should read this.
                            Code:
                            <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                                <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
                            </bean>

                            Comment


                            • #15
                              Originally posted by karldmoore View Post
                              Apologies, it should read this.
                              Code:
                              <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                                  <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
                              </bean>
                              I know but this didn't solve the problem about why my app couldn't load db driver...

                              C

                              Comment

                              Working...
                              X