java - JBOSS eap 6.1.0 中的 Spring 框架 JNDI 配置问题

标签 java spring jboss jndi jboss6.x

我已经在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

对这里出了什么问题有什么想法吗?

最佳答案

尝试将 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" />

关于java - JBOSS eap 6.1.0 中的 Spring 框架 JNDI 配置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39852738/

相关文章:

jakarta-ee - 在没有 WAR 的情况下在 EAR 中部署多个 "Web Fragment"项目

gwt - 远程调用ejb

java - JNI : Invoke JAVA method from C++, 返回对象、引用和 GC

java - 为什么我们应该在 File.toPath() (jdk7) 中使用临时变量

java - 浏览器或 Docker 无法访问使用 SSL 的 Nexus Repository Manager 3

mysql - 具有自定义结果的 Spring CrudRepository 查询

java - 如何为 lombok 编写具有单一注释的集合数据类型的自定义 build() 函数?

java - 仅 Autowiring 构造函数的某些参数

java - Spring 的 MockHttpServlet(Request|Response) 替代品?

java - 在 JBoss Seam 中修剪输入