Wildfly 9数据源spring jpa在openshift上缺少依赖项错误

时间:2015-10-15 13:42:46

标签: spring-data wildfly postgresql-9.2

我想使用来自wildfly9的datasource部署一个带有spring jpa的应用程序,我想我需要所有配置但是我收到错误。

我拥有的是什么 子系统中的standalon.xml

<datasource jndi-name="java:jboss/datasources/PostgreSQLDS" 
   jta="true" enabled="${postgresql.enabled}"
   use-java-context="true" 
   pool-name="PostgreSQLDS" 
   use-ccm="true">
             <connection-url>
jdbc:postgresql://${env.OPENSHIFT_POSTGRESQL_DB_HOST}:${env.OPENSHIFT_POSTGRESQL_DB_PORT}/${env.OPENSHIFT_APP_NAME}
             </connection-url>
             <driver>postgresql</driver>
           <security>
                      <user-name>${env.OPENSHIFT_POSTGRESQL_DB_USERNAME}
             </user-name>
             <password>
                ${env.OPENSHIFT_POSTGRESQL_DB_PASSWORD}
             </password>
           </security>
           <validation>
             <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
             <background-validation>true</background-validation>
             <background-validation-millis>60000</background-validation-millis>
            </validation>
            <pool>
               <flush-strategy>IdleConnections</flush-strategy>
            </pool>
 </datasource>
 <drivers>
    <driver name="postgresql" module="org.postgresql.jdbc">
                        <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
    </driver>
 </drivers>

我的spring.profile.xml有

<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <beans:property name="jndiName" value="java:jboss/datasources/PostgreSQLDS"/>
</beans:bean>

我得到的错误是

[0m[31m08:57:40,995 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "ROOT.war")]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.persistenceunit.\"ROOT.war#my-jpa\".__FIRST_PHASE__ is missing [jboss.naming.context.java.\"\\n            java:comp\".env.jdbc.\"PostgreSQLDS\\n        \"]",
"jboss.persistenceunit.\"ROOT.war#my-jpa\" is missing [jboss.naming.context.java.\"\\n            java:comp\".env.jdbc.\"PostgreSQLDS\\n        \"]"

]}

我不确定我做得不好,欢迎任何帮助

1 个答案:

答案 0 :(得分:0)

使用 java:comp / env 尝试此JNDI资源映射,您需要使用下面的jboss-web.xml在您的应用中使用数据源资源。

<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <beans:property name="jndiName" value="java:comp/env/jdbc/PostgreSQLDS"/>
</beans:bean>

使用此内容在WEB-INF文件夹中添加jboss-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://www.jboss.com/xml/ns/javaee
      http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
   <context-root>/myAppRoot</context-root>

   <resource-ref>
        <res-ref-name>jdbc/PostgreSQLDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <jndi-name>java:jboss/datasources/PostgreSQLDS</jndi-name>
    </resource-ref>

</jboss-web>