java - spring 和 JBoss7 中的 jndi 查找问题

标签 java spring jboss7.x datasource jndi

我在我的项目中使用 Spring、JPA 和 JBoss 7。

我在 jndi 查找数据源时收到以下错误,如下所示

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/rulesUI]] (MSC service thread 1-4) StandardWrapper.Throwable: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rulesDataSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Error looking up RuleDS, service service jboss.naming.context.java.RuleDS is not started

这是我在 JBoss 中配置数据源的standalone.xml。

<datasource jndi-name="java:/RuleDS" pool-name="rule_poc_schema" enabled="true" use-java-context="true" spy="true">
                    <connection-url>jdbc:oracle:thin:@medicare-ins.cxgvce1cqpuy.us-east-1.rds.amazonaws.com:3306:MEDICARE</connection-url>
                    <driver>oracle</driver>
                    <security>
                        <user-name>APPLICATION_MEA_DEV</user-name>
                        <password>password</password>
                    </security>
                </datasource>

在我的 Spring 配置文件中,我使用以下方式访问它:

<jee:jndi-lookup jndi-name="java:/RuleDS" id="rulesDataSource"/>

请帮助我。

最佳答案

可以尝试这样:

在 Spring Context 中我们有:

  <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:jboss-datasource" /> 
  </bean>

在 Jboss 我有这样的:

<datasources>
    <local-tx-datasource>
        <jndi-name>jboss-datasource</jndi-name>
        <connection-url>jdbc:mysql://127.0.0.1:3306/shoppingDB</connection-url>
        <driver-class>com.mysql.jdbc.Driver</driver-class>
        <user-name>root</user-name>
        <password>123456</password>
        <exception-sorter-class-name>
            org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
        </exception-sorter-class-name>
        <metadata>
            <type-mapping>MySql</type-mapping>
        </metadata>
        <check-valid-connection-sql>select 1</check-valid-connection-sql>
    </local-tx-datasource>
</datasources>

确保你已经有 spring-context jar

希望这有帮助,

问候

关于java - spring 和 JBoss7 中的 jndi 查找问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16044712/

相关文章:

java - JBoss AS 7 中的 hibernate 是否需要 c3p0 连接池

java - CDI 跨容器注入(inject)

jboss7.x - Drools规则错误 "Unexpected global"

Java - 按值传递 - 垃圾收集

java - 如何: Eclipse Maven install build jar with dependencies

java - 如何编辑从 xsd 生成的 java 类

java - cxf spring 配置无法加载,缺少 xsd

java - 无法 Autowiring 自定义用户详细信息

java - 如何获取我们自定义的AlertDialog的值?

java - 获取 InvalidMappingException : Could not parse mapping document from resource