错误新的缺失/不满足的依赖项:(无法配置数据源)

时间:2012-10-31 12:51:13

标签: jpa jboss jboss7.x

我有一个使用JSF(Primefaces),JPA(Hibernate)和EJB的Web应用程序,并且无法在JBoss上配置数据源。我收到以下错误:

2012/10/31 07:20:17,948 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)

2012/10/31 07:20:18,836 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "ROOT.war" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"ROOT.war#test\"jboss.naming.context.java.jboss.datasources.MysqlDSMissing[jboss.persistenceunit.\"ROOT.war#test\"jboss.naming.context.java.jboss.datasources.MysqlDS]"]}

2012/10/31 07:20:19,252 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment ROOT.war in 413ms

2012/10/31 07:20:19,255 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report

JBAS014775:    New missing/unsatisfied dependencies:

      service jboss.naming.context.java.jboss.datasources.MysqlDS (missing) dependents: [service jboss.persistenceunit."ROOT.war#test"]

2012/10/31 07:20:19,334 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"ROOT.war#test\"jboss.naming.context.java.jboss.datasources.MysqlDSMissing[jboss.persistenceunit.\"ROOT.war#test\"jboss.naming.context.java.jboss.datasources.MysqlDS]"]}}}

您可以在下面看到我的persistence.xmlstanadlone.xmlpom.xml我错过了pom.xml中的一些依赖项吗?

的persistence.xml

   <provider>org.hibernate.ejb.HibernatePersistence</provider> 

<jta-data-source>java:jboss/datasources/MysqlDS</jta-data-source> 

<properties>

  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>    

  <property name="hibernate.show_sql" value="true"/>

  <property name="hibernate.max_fetch_depth" value="3"/>

  <property name="hibernate.hbm2ddl.auto" value="update" />

</properties>

Standalone.xml

<datasources>
            <datasource jndi-name="java:jboss/datasources/ExampleDS" enabled="true" use-java-context="true" pool-name="H2DS">
                <connection-url>jdbc:h2:${jboss.server.data.dir}/test;DB_CLOSE_DELAY=-1</connection-url>
                <driver>h2</driver>
            <security>
                    <user-name>sa</user-name>
                    <password>sa</password>
                </security>
            </datasource>
            <datasource jndi-name="java:jboss/datasources/MysqlDS" enabled="${mysql.enabled}" use-java-context="true" pool-name="MysqlDS">
                <connection-url>jdbc:mysql://127.5.54.1:3306/researchprojects</connection-url>
                <driver>mysql</driver>
                <security>
                  <user-name>admin</user-name>
                  <password>*******</password>
                </security>
                <validation>
                  <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
                </validation>
            </datasource>
            <datasource jndi-name="java:jboss/datasources/PostgreSQLDS" enabled="${postgresql.enabled}" use-java-context="true" pool-name="PostgreSQLDS" use-ccm="true">
                <connection-url>jdbc:postgresql://${env.OPENSHIFT_DB_HOST}:${env.OPENSHIFT_DB_PORT}/${env.OPENSHIFT_APP_NAME}</connection-url>
                <driver>postgresql</driver>
                <security>
                  <user-name>${env.OPENSHIFT_DB_USERNAME}</user-name>
                  <password>${env.OPENSHIFT_DB_PASSWORD}</password>
                </security>
                <validation>
                  <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
                </validation>
            </datasource>
            <drivers>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
                <driver name="mysql" module="com.mysql.jdbc">
                    <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                </driver>
                <driver name="postgresql" module="org.postgresql.jdbc">
                    <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
                </driver>
            </drivers>
        </datasources> 

的pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>openshifttest</groupId>
  <artifactId>openshifttest</artifactId>
  <packaging>war</packaging>
  <version>1.0</version>
  <name>openshifttest</name>

 <repositories>
  <repository>
        <id>scala</id>
        <name>Scala Tools</name>
        <url>http://scala-tools.org/repo-releases/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
  <repository>  
    <id>prime-repo</id>  
    <name>PrimeFaces Maven Repository</name>  
    <url>http://repository.primefaces.org</url>  
    <layout>default</layout>  
    </repository>
</repositories>   

    <pluginRepositories>
        <pluginRepository>
            <id>scala</id>
            <name>Scala Tools</name>
            <url>http://scala-tools.org/repo-releases/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.jboss.spec</groupId>
      <artifactId>jboss-javaee-6.0</artifactId>
      <version>1.0.0.Final</version>
      <type>pom</type>
      <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.7.2</version>
    </dependency>
    <dependency>  
        <groupId>org.primefaces</groupId>  
        <artifactId>primefaces</artifactId>  
        <version>3.4.1</version>  
    </dependency>
  </dependencies>

  <profiles>
    <profile>
     <!-- When built in OpenShift the 'openshift' profile will be used when invoking mvn. -->
     <!-- Use this profile for any OpenShift specific customization your app will need. -->
     <!-- By default that is to put the resulting archive into the 'deployments' folder. -->
     <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
     <id>openshift</id>
     <build>
        <finalName>openshifttest</finalName>
        <plugins>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
              <outputDirectory>deployments</outputDirectory>
              <warName>ROOT</warName>
            </configuration>
          </plugin>
          <plugin>
                <groupId>org.scala-tools</groupId>
               <artifactId>maven-scala-plugin</artifactId>

                <executions>
                    <execution>
                        <id>compile</id>
                        <goals>
                        <goal>compile</goal>
                        </goals>
                        <phase>compile</phase>
                    </execution>

                    <execution>
                        <id>test-compile</id>
                        <goals>
                        <goal>testCompile</goal>
                        </goals>
                        <phase>test-compile</phase>
                    </execution>

                    <execution>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

有人能告诉我我做错了什么吗?

8 个答案:

答案 0 :(得分:3)

你启用了mysql数据源吗?默认为禁用。

配置的一部分

<datasource jndi-name="java:jboss/datasources/MysqlDS" enabled="${mysql.enabled}" use-java-context="true" pool-name="MysqlDS">

有标志$ {mysql.enabled},它是系统属性,在启用了mysql的情况下启用数据源。

查看指南http://jaitechwriteups.blogspot.com/2011/08/deploy-java-ee-application-on-openshift.html

并搜索“使用OpenShift Express中可用的MySQL数据库”一章

显示您缺少的配置部分。

答案 1 :(得分:3)

迟到了,但是在收到此错误并检查了大量内容之后,事实证明我只是在standalone.xml中保留了驱动程序的定义

<drivers> <driver name="mysql" module="com.mysql"> <xa-datasource-class>com.mysql.jdbc.Driver</xa-datasource-class> </driver> </drivers>

因此,要检查的步骤是:

  1. 将jar文件mysql-connector-java-5.1.13-bin.jar添加到jboss-eap-6.1 / modules / com / mysql / main

  2. 将module.xml文件添加到jboss-eap-6.1 / modules / com / mysql / main

  3. `

    <module xmlns="urn:jboss:module:1.1" name="com.mysql"><resources>
    <resource-root path="mysql-connector-java-5.1.13-bin.jar"/>
    </resources>
    <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
    <module name="javax.servlet.api" optional="true"/>
    </dependencies>
    </module>
    

    `

    3.将此添加到standalone.xml `

           <datasource jndi-name="java:jboss/datasources/MySqlDS"
              pool-name="MySqlDS" enabled="true"
              use-java-context="true" jta="true" use-ccm="true">
                <connection-url>jdbc:mysql://localhost:3306/testDB</connection-url>
                <driver-class>com.mysql.jdbc.Driver</driver-class>
                <driver>mysql</driver>
    
                <security>
                    <user-name>root</user-name>
                    <password></password>
                </security>
           </datasource>
            <drivers>
                <driver name="mysql" module="com.mysql">
                    <xa-datasource-class>com.mysql.jdbc.Driver</xa-datasource-class>
                </driver>
            </drivers>
    

    4. in your web app persistance.xml, add this line

    的java:JBoss的/数据源/ MySqlDS

    `

    希望这有助于某人!

答案 2 :(得分:1)

您需要将JDBC驱动程序正确安装为JBoss 7模块。

一个。创建文件夹JBOSS_HOME \ modules \ com \ mysql \ main(是的,主子文件夹必须在那里)

湾将JDBC驱动程序复制到该文件夹​​

℃。使用以下内容在该文件夹module.xml文件中创建:

<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.0" name="com.mysql">
  <resources>
    <resource-root path="mysql-connector-java-5.1.6-bin.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>

其中mysql-connector-java-5.1.6-bin.jar必须由您的驱动程序名称替换。请注意,对于此类模块配置,您需要将驱动程序定义中的module名称更改为com.mysql(这是一种名称约定),或者只需在module.xml中重命名模块名称。

重新启动服务器后,您应该在JBOSS_HOME \ modules \ com \ mysql \ main中看到一个新文件.index。

我在JBoss 7.1.1.Final

上测试过

答案 3 :(得分:1)

如果要在web.xml中将数据源指定为资源引用,则将名称​​完全与standalone.xml(或domain.xml)中的名称匹配:

<强>的web.xml

 <resource-ref>
  <res-ref-name>java:jboss/datasources/OracleDS</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
 </resource-ref>

<强> standalone.xml

<datasource jndi-name="java:jboss/datasources/OracleDS" pool-name="OracleDS" enabled="true" use-java-context="false">

答案 4 :(得分:1)

在我的案例中,persistence.xml中存在拼写问题

<jta-data-source>java:jboss/datasources/mydb</jta-data-source>

必须匹配:

<datasource jta="true" jndi-name="java:jboss/datasources/mydb" pool-name="EmployeeDb" enabled="true" use-ccm="false">

答案 5 :(得分:0)

有同样的问题。几个小时后,我找到了解决方案:

https://docs.jboss.org/author/display/AS7/How+do+I+migrate+my+application+from+AS5+or+AS6+to+AS7

  

确保在module.xml文件的开头没有空格   或者你会得到一个“新的遗漏/不满意的依赖”错误   这个司机。

卫生署!

答案 6 :(得分:0)

您应该考虑尝试设置不同版本的mysql驱动程序。

mysql-connector-java-5.1.17-bin worked fine for me.

我希望你觉得这很有用,

感谢。

答案 7 :(得分:0)

如果您对数据源配置没问题。 确保你安装了jboss开发工具包来从eclipse市场进行eclipse。 它会起作用。