Spring无法查找jdbc配置的数据源

时间:2010-11-15 15:02:38

标签: spring jndi jta

我已经在tomcat 5.5上部署了我的应用程序,IDE是eclipse with myeclipse插件。当我尝试启动tomcat服务器时,我收到以下错误:

  

错误 - ContextLoader.initWebApplicationContext(219)|上下文初始化失败   org.springframework.beans.factory.BeanCreationException:在ServletContext资源[/WEB-INF/xaconfig/daoJPAConfig.xml]中定义了名为'dataSource'的bean创建错误:init方法的调用失败;嵌套异常是javax.naming.NameNotFoundException:名称java:comp未绑定在此Context中    在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412)    在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)    在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)    at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:291)    在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)    在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)    在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)    在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:546)    在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)    在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)    在org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)    在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)    在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3669)    在org.apache.catalina.core.StandardContext.start(StandardContext.java:4104)    在org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)    在org.apache.catalina.core.StandardHost.start(StandardHost.java:718)    在org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)    在org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)    在org.apache.catalina.core.StandardService.start(StandardService.java:450)    在org.apache.catalina.core.StandardServer.start(StandardServer.java:683)    在org.apache.catalina.startup.Catalina.start(Catalina.java:537)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)    在java.lang.reflect.Method.invoke(Method.java:597)    在org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)    在org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)   引发者:javax.naming.NameNotFoundException:名称java:comp未绑定在此Context中    在org.apache.naming.NamingContext.lookup(NamingContext.java:778)    在org.apache.naming.NamingContext.lookup(NamingContext.java:161)    在javax.naming.InitialContext.lookup(InitialContext.java:392)    在org.springframework.jndi.JndiTemplate $ 1.doInContext(JndiTemplate.java:154)    在org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)    在org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)    在org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)    在org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)    在org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)    在org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)    在org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)    在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)    在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)    ......还有27个

我已将Apache Software Foundation \ Tomcat 5.5 \ conf中的数据源配置为:

  <GlobalNamingResources>
    <Environment
      name="simpleValue"
      type="java.lang.Integer"
      value="30"/>
    <Resource
      name="jdbc/Paymentsdb"
      type="javax.sql.DataSource"
      maxActive="20"
      maxIdle="10"
      username="root"
      maxWait="20000"
      validationQuery="SELECT=1"
      driverClassName="com.mysql.jdbc.Driver"
      password="root"
      url="jdbc\:mysql\://devserver\:3306/payhub"/>
    <Resource
      auth="Container"
      description="User database that can be updated and saved"
      name="UserDatabase"
      type="org.apache.catalina.UserDatabase"
      factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
      pathname="conf/tomcat-users.xml"/>
  </GlobalNamingResources>

我添加了Apache Software Foundation \ Tomcat 5.5 \ conf \ context.xml页面 我添加了我的webInf \ web.xml

 <resource-ref>
   <description>PaymentsDatabase</description>
   <res-ref-name>jdbc/Paymentsdb</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>

我正在使用spring框架,hybernate + jpa。请告诉我,问题可能是什么?

1 个答案:

答案 0 :(得分:0)

我不建议将其放在Tomcat的全局配置中。无法保证您可以访问它。最好把它放在META-INF / context.xml中。

您没有显示JNDI数据源的Spring配置。请加上。

  

嵌套异常是   javax.naming.NameNotFoundException:   名称java:comp未绑定在此   上下文

这不应该是java:comp/env吗?