在一个SSH工程中,原来数据源是配置在XML中的,如下:
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc/cms_proDS</value>  
</property>
</bean> 现在把它转移到了一个properties文件里,配置进行了如下改动:
XML:
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>${db.datasource.jndiName}</value>  
</property>
</bean>   properties文件:
db.datasource.jndiName=jdbc/cms_proDS结果就找不到数据源了。我使用的容器是WAS6.1,不知是否和这有关。

解决方案 »

  1.   

    好好检查下PropertyConfigurer中properties文件的路径
      

  2.   


    在Spring中使用properties,要先加载之
    写个东西判断是否正确加载进来了,一般加载失败的原因是路径问题
      

  3.   

    路径问题,可是用在tomcat里就是好的啊。
    db.datasource.jndiName=java\:comp/env/jdbc/AHCMS2DS
      

  4.   

    我把Was日志的异常贴出来看看吧。localhostNode01Cell/nodes/localhostNode01/servers/server1, name: jdbc/AHCMS2DS : First component in name AHCMS2DS  not found.
    javax.naming.NameNotFoundException: Context: localhostNode01Cell/nodes/localhostNode01/servers/server1, name: jdbc/AHCMS2DS : First component in name AHCMS2DS  not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
    at com.ibm.ws.naming.jndicos.CNContextImpl.processNotFoundException(CNContextImpl.java:4730)
    at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1907)
    at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1862)
    at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1552)
    at com.ibm.ws.naming.jndicos.CNContextImpl.lookup(CNContextImpl.java:1354)
    at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:172)
    at javax.naming.InitialContext.lookup(InitialContext.java:363)
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:123)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:121)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:146)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:86)
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:104)
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:125)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:176)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
    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:275)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:320)
    at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
    at org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:83)
    at javax.servlet.GenericServlet.init(GenericServlet.java:256)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:185)
    at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.init(ServletWrapper.java:316)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.initialize(ServletWrapper.java:1119)
    at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.initialize(ServletWrapper.java:149)
    at com.ibm.wsspi.webcontainer.extension.WebExtensionProcessor.createServletWrapper(WebExtensionProcessor.java:99)
    at com.ibm.ws.webcontainer.webapp.WebApp.initializeTargetMappings(WebApp.java:480)
    at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinish(WebApp.java:275)
    at com.ibm.ws.wswebcontainer.webapp.WebApp.initialize(WebApp.java:272)
    at com.ibm.ws.wswebcontainer.webapp.WebGroup.addWebApplication(WebGroup.java:88)
    at com.ibm.ws.wswebcontainer.VirtualHost.addWebApplication(VirtualHost.java:157)
    at com.ibm.ws.wswebcontainer.WebContainer.addWebApp(WebContainer.java:655)
    at com.ibm.ws.wswebcontainer.WebContainer.addWebApplication(WebContainer.java:608)
    at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:333)
    at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:549)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1295)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1129)
    at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:567)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:814)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:948)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl$AppInitializer.run(ApplicationMgrImpl.java:2114)
    at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:340)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1510)
    Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
    at com.ibm.ws.naming.ipcos.WsnOptimizedNamingImpl.do_resolve_complete_info(WsnOptimizedNamingImpl.java:543)
    at com.ibm.ws.naming.cosbase.WsnOptimizedNamingImplBase.resolve_complete_info(WsnOptimizedNamingImplBase.java:2215)
    at com.ibm.WsnOptimizedNaming._NamingContextStub.resolve_complete_info(_NamingContextStub.java:536)
    at com.ibm.ws.naming.jndicos.CNContextImpl.cosResolve(CNContextImpl.java:4351)
    at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1901)
    ... 52 more