Announcement Announcement Module
Collapse
No announcement yet.
Hibernate - MySQL - Error connecting Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate - MySQL - Error connecting

    Hello.

    I've put Hibernate to my MySQL well configured persistence. I am following the instructions correctly (I believe), but somehow it is not connecting propperly.

    hibernate.cfg.xml:

    Code:
    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    
    <hibernate-configuration>
        <session-factory>
            <!-- JDBC connection pool (use the built-in) -->
            <property name="connection.pool_size">1</property>
    
            <!-- Enable Hibernate's automatic session context management -->
            <property name="current_session_context_class">thread</property>
    
            <!-- Disable the second-level cache  -->
            <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
            <!-- Echo all executed SQL to stdout -->
            <property name="show_sql">true</property>
    
            <!-- Drop and re-create the database schema on startup -->
            <property name="hbm2ddl.auto">create</property>
    
            <mapping resource="spring/domain/Product.hbm.xml" />
        </session-factory>
    </hibernate-configuration>
    hibernate.properties

    Code:
    hibernate.connection.driver_class = com.mysql.jdbc.Driver
    hibernate.connection.url = jdbc:mysql://localhost:3306/consulta
    hibernate.connection.username = ElPiter
    hibernate.connection.password =
    hibernate.dialect = org.hibernate.dialect.MySQLDialect
    stacktrace:

    Code:
    org.hibernate.exception.GenericJDBCException: Cannot open connection
    	org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
    	org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
    	org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    	org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
    	org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
    	org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
    	org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
    	org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
    	org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1353)
    	org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:558)
    	org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:374)
    	org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:263)
    	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101)
    	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	$Proxy0.getProducts(Unknown Source)
    	springapp.web.InventoryController.command(InventoryController.java:36)
    	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	java.lang.reflect.Method.invoke(Method.java:585)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
    	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    Any clue??

    Thank you

  • #2
    1) remove your current_session_context thread that screws up springs integration
    2) don't use spaces in your properties file!
    3) Why use an cfg.xml a .properties and a spring configuration file to configure hibernate seems a bit over complex...

    Comment


    • #3
      ok... thank you for your replay. Nothing changed, though...

      Let me extend the error just for people to see if it's more helpful and can help me:

      Code:
      org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection
      	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583)
      	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      The reason for "multiconfiguration" is because I have been trying everything step by step and this is how it looks like now. I'll fix it. But first I need this to work :S

      Thanks again

      Comment


      • #4
        Code:
        java.net.ConnectException: Connection refused
        	at java.net.PlainSocketImpl.socketConnect(Native Method)
        	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:430)
        	at java.net.Socket.connect(Socket.java:520)
        	at java.net.Socket.connect(Socket.java:470)
        	at java.net.Socket.<init>(Socket.java:367)
        	at java.net.Socket.<init>(Socket.java:209)
        	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
        	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
        	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2043)
        	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
        	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
        	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
        	at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
        	at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
        	at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
        	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
        	at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
        	at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:82)
        	at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
        	at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
        	at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
        	at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
        	at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1353)
        	at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:558)
        	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:374)
        	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:263)
        	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101)
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        	at $Proxy0.getProducts(Unknown Source)
        	at springapp.web.InventoryController.command(InventoryController.java:36)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        	at java.lang.reflect.Method.invoke(Method.java:585)
        	at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473)
        	at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
        	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
        	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
        	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
        	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
        	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
        	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
        	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        	at java.lang.Thread.run(Thread.java:613)

        Comment


        • #5
          error changed...

          The behavour of this is not very normal...

          I open the port in the firewall of my MacOS X. I got this at least to try to connect or something. The problem now is very simple: it doesn't find the hibernate.cfg.xml. I have it in the same folder where I have my HibernateUtil.class.

          HibernateUtil:

          Code:
          package springapp.repository.hibernate;
          
          import java.io.File;
          
          import org.hibernate.SessionFactory;
          import org.hibernate.cfg.Configuration;
          
          public class HibernateUtil {
              private static final SessionFactory sessionFactory;
              static {
                  try {
                      // Create the SessionFactory from hibernate.cfg.xml
                      sessionFactory = new Configuration().configure(new File("hibernate.cfg.xml"))
                              .buildSessionFactory();
                  } catch (Throwable ex) {
                      // Make sure you log the exception, as it might be swallowed
                      System.err.println("Initial SessionFactory creation failed." + ex);
                      throw new ExceptionInInitializerError(ex);
                  }
              }
          
              public static SessionFactory getSessionFactory() {
                  return sessionFactory;
              }
          }
          Actual stacktrace:

          Code:
          GRAVE: Servlet.service() para servlet springapp lanz´┐? excepci´┐?n
          java.io.FileNotFoundException: hibernate.cfg.xml (No such file or directory)
          	at java.io.FileInputStream.open(Native Method)
          	at java.io.FileInputStream.<init>(FileInputStream.java:106)
          	at org.hibernate.cfg.Configuration.configure(Configuration.java:1496)
          	at springapp.repository.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:13)
          	at springapp.repository.hibernate.HibernateProductDao.getProductList(HibernateProductDao.java:29)
          	at springapp.service.SimpleProductManager.getProducts(SimpleProductManager.java:14)
          	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          	at java.lang.reflect.Method.invoke(Method.java:585)
          	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
          	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
          	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
          	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
          	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
          	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
          	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
          	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
          	at $Proxy0.getProducts(Unknown Source)
          	at springapp.web.InventoryController.command(InventoryController.java:36)
          	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          	at java.lang.reflect.Method.invoke(Method.java:585)
          	at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473)
          	at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
          	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
          	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
          	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
          	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
          	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
          	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
          	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
          	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
          	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
          	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
          	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
          	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
          	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
          	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
          	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
          	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
          	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
          	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
          	at java.lang.Thread.run(Thread.java:613)
          Any clue?

          Thanks

          Comment


          • #6
            It is easier to configure a LocalSessionFactoryBean in your applicationContext and use that instead of the utility class. You could still have the username etc. in a properties file. Something like the following would work. You could still use the HIbernateUtil in a modified way.

            Configuration
            Code:
            <bean class="org.springframework.beans.factory.PropertyPlaceHolderConfigurer">
            	<property name="locations" value="classpath:hibernate.properties" />
            </bean>
            
            <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            	<property name="username" value="${hibernate.connection.username}" />
            	<property name="password" value="${hibernate.connection.password}" />
            	<property name="url" value="${hibernate.connection.url}" />
            	<property name="driverClassName" value="${hibernate.connection.driver_class}" />
            	<property name="initialSize" value="5" />
            	<property name="maxActive" value="20" />
            </bean>
            
            <bean id="sessionFactory" class="LocalSessionFactoryBean">
            	<property name="dataSource" ref="dataSource" />
            	<property name="hibernateProperties">
            		<value>
            			hibernate.dialect=${hibernate.dialect}
            			cache.provider_class=org.hibernate.cache.NoCacheProvider
            			show_sql=true
            			hbm2ddl.auto=create
            		</value>
            	</property>
            	<property name="mappingResources">
            		<list>
            			<value>spring/domain/Product.hbm.xml</value>
            		</list>
            	</property>
            </bean>
            
            <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            	<property name="sessionFactory" ref="sessionFactory" />
            	<property name="dataSource" ref="dataSource" />
            </bean>
            
            <!-- Configure HibernateUtil for migration strategy -->
            <bean class="HibernateUtil">
            	<property name="sessionFactory" ref="sessionFactory" />
            </bean>
            Modified HibernateUtil
            Code:
            package springapp.repository.hibernate;
            
            import java.io.File;
            
            import org.hibernate.SessionFactory;
            import org.hibernate.cfg.Configuration;
            
            /**
            *@deprecated preferred way is to inject SessionFactory into classes instead of using HibernateUtil
            */
            public class HibernateUtil {
                private static final SessionFactory sessionFactory;
            
                public static SessionFactory getSessionFactory() {
            		if (sessionFactory == null) {
            			throw new IllegalStateException("getSessionFactory called before proper initialization!");
            		}
            		return sessionFactory;
                }
            	
            	public void setSessionFactory(SessionFactory sessionFactory) {
            		sessionFactory=sessionFactory;
            	}
            }
            Now you have everything configured in Spring (no need for the hibernate.cfg.xml) only the hibernate.properties for externalizing the configuration.

            Comment


            • #7
              where should it be located hibernate.properties?

              Hello.

              Thanks again. Good solution. I have a mess here :S.

              Where should it be located hibernate.properties? Spring doesn't resolve the keys :S

              Thanks again

              Comment


              • #8
                With the configuration I posted it should be in the root of the classpath.

                The reference guide explains how resource loading works and what the classpath: and other prefixes mean.

                Comment


                • #9
                  horrible

                  Hello.

                  I don't get it yet. I think I'm doing right. hibernate.properties is in the class folder. keys are ok and applicationContext.xml is ok.

                  I don't know what else to check...

                  Stacktrace again:

                  Code:
                  GRAVE: Context initialization failed
                  org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Could not resolve placeholder 'hibernate.connection.username'
                  	at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:268)
                  	at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
                  	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:553)
                  	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:527)
                  	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:362)
                  	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
                  	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
                  	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
                  	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
                  	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
                  	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
                  	at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
                  	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
                  	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
                  	at org.apache.catalina.core.StandardService.start(StandardService.java:516)
                  	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
                  	at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                  	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                  	at java.lang.reflect.Method.invoke(Method.java:585)
                  	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
                  	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
                  04-may-2009 0:46:26 org.apache.catalina.core.StandardContext listenerStart
                  GRAVE: Excepci´┐?n enviando evento inicializado de contexto a instancia de escuchador de clase org.springframework.web.context.ContextLoaderListener
                  org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Could not resolve placeholder 'hibernate.connection.username'
                  	at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:268)
                  	at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
                  	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:553)
                  	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:527)
                  	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:362)
                  	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
                  	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
                  	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
                  	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
                  	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
                  	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
                  	at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
                  	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
                  	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
                  	at org.apache.catalina.core.StandardService.start(StandardService.java:516)
                  	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
                  	at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                  	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                  	at java.lang.reflect.Method.invoke(Method.java:585)
                  	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
                  	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
                  04-may-2009 0:46:26 org.apache.catalina.core.StandardContext start
                  GRAVE: Error listenerStart
                  I'm going to bed.

                  Thanks again.

                  Comment


                  • #10
                    It is very likely that something down the datasource definition chain is not correct.

                    Comment


                    • #11
                      Is the properties file in the ROOT of the class directory (I assume you mean classes in the WEB-INF directory?). Else try changing classpath: to classpath:/ (although I thought that spring strips the leading slash).

                      Also make sure that all the keys are in the properties file and that they are correct (also check my spelling because I did it from the top of my head).

                      Comment


                      • #12
                        Still didn't get it.

                        Hello.

                        Re-taking this. Any help?

                        Thank you again, Marten.

                        But I still have this problem.

                        I know this has to be very simple. I am not getting to read from a properties file. (hibernate.properties)

                        In applicationContext.xml I have this:

                        Code:
                        <bean class="org.springframework.beans.factory.PropertyPlaceHolderConfigurer">
                        		<property name="locations" value="classpath:./hibernate.properties" />
                        </bean>
                        
                        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
                        		<property name="username" value="${hibernate.connection.username}" />
                        		<property name="password" value="${hibernate.connection.password}" />
                        		<property name="url" value="${hibernate.connection.url}" />
                        		<property name="driverClassName" value="${hibernate.connection.driver_class}" />
                        		<property name="initialSize" value="5" />
                        		<property name="maxActive" value="20" />
                        </bean>
                        And in the hibernate.properties I have:

                        Code:
                        hibernate.connection.driver_class=com.mysql.jdbc.Driver
                        hibernate.connection.url=jdbc:mysql://localhost:3306/consulta
                        hibernate.connection.username=ElPiter
                        hibernate.connection.password=password
                        hibernate.dialect=org.hibernate.dialect.MySQLDialect
                        However, I am getting this error when creating context (starting up Tomcat Server):

                        Code:
                        GRAVE: Context initialization failed
                        org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Could not resolve placeholder 'hibernate.connection.username'
                        The properties file is in WEB-INF/classes. And the spelling is correct. As far as I checked it N-1 times

                        Obviously something must be wrong. But I don't get what it is.
                        Would you take a new look?

                        Thanks, Pedro
                        Last edited by pgbonino; May 10th, 2009, 05:37 AM. Reason: changing greetings

                        Comment


                        • #13
                          Enable debug logging and see if the file gets read. If it isn't it isn't in the location you think it is...

                          Comment

                          Working...
                          X