【问题标题】:Issue in jndi lookup in spring and JBoss7spring 和 JBoss7 中的 jndi 查找问题
【发布时间】:2013-04-09 07:27:19
【问题描述】:

我在我的项目中使用 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"/>

请帮帮我。

【问题讨论】:

    标签: java spring jboss7.x datasource jndi


    【解决方案1】:

    可以这样试试:

    在 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

    希望这会有所帮助,

    问候

    【讨论】:

      【解决方案2】:

      首先我会检查日志中的以下行:

      [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source [java:/RuleDS]
      

      我也用全名:

      java:jboss/datasources/MyDSName
      

      也许是这样?

      【讨论】:

      • 上面的名字应该用在standalone.xml文件还是spring配置文件中?
      • 两者都有,但我不认为是这种情况,你可以试试。我在 jboss 指南中看到了你的例子。先看看Jboss注册是否正确。转到管理控制台localhost:9990/console -> 从左侧菜单中选择运行时和数据源。您应该会看到 Name、JNDI 和 Enabled 状态
      猜你喜欢
      • 2012-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多