我在Jboss eap 6.1.0服务器中部署了war文件。我在我的项目中使用Spring框架。我使用两个文件配置了JNDI,即sample-ds.xml(保存在JBOSS部署文件夹下)和dataSourceConfiguration.xml(它是war文件的一部分,由applicationContext.xml文件加载)。 dataSourceConfiguration.xml如下:
<beans>
<jee:jndi-lookup id="awd" jndi-name="CS/AWD_QA" resource-ref="false" />
<!-- Don't change the id of the bean com.dsths.cs.awd.utils.RoutingDataSource -->
<bean id="routingDataSource" class="com.dsths.cs.awd.utils.RoutingDataSource">
<property name="targetDataSources">
<map key-type="java.lang.String"></map>
</property>
</bean>
我的sample-ds.xml如下:
<datasources>
<datasource enabled="true" jndi-name="java:jboss/CS/AWD_QA" jta="true" pool-name="AWDCS" use-ccm="true" use-java-context="false">
<connection-url>jdbc:oracle:thin:@XXXXX:1521:AWD</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<transaction-isolation>TRANSACTION_NONE</transaction-isolation>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>10</max-pool-size>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>sample</user-name>
<password>sample</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
<use-fast-fail>false</use-fast-fail>
<exception-sorter class-name="org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter"/>
</validation>
<timeout>
<idle-timeout-minutes>15</idle-timeout-minutes>
<xa-resource-timeout>0</xa-resource-timeout>
</timeout>
<statement>
<track-statements>false</track-statements>
</statement>
</datasource>
</datasources>
</beans>
当我使用上面的JNDI配置部署war文件时,我收到以下错误:
Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AWDScriptController': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private com.dsths.cs.awd.services.ScriptTextFetcherService com.dsths.cs.awd.rest.ws.AWDScriptController.scriptService; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scriptTextFetcherService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dsths.cs.awd.dao.AWDFormDao com.dsths.cs.awd.services.ScriptTextFetcherService.awdDao;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AWDFormDao':
Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource com.dsths.cs.awd.dao.AWDFormDao.dataSource; nested exception is org.springframework.beans.
factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=awd)}
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'awd': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: CS/AWD_QA – service jboss.naming.context.java.CS.AWD_QA
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'awd': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: CS/AWD_QA – service jboss.naming.context.java.CS.AWD_QA
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'awd': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: CS/AWD_QA
关于这里出了什么问题的任何想法?
答案 0 :(得分:0)
尝试将java:jboss/
添加到数据源名称。
<jee:jndi-lookup id="awd" jndi-name="java:jboss/CS/AWD_QA" resource-ref="false" />
如果这不起作用,您可以将数据源的名称更改为
的java:/ JDBC / CS / AWD_QA
<jee:jndi-lookup id="awd" jndi-name="java:/jdbc/CS/AWD_QA" resource-ref="false" />