3

我有一个使用 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.xml,stanadlone.xmlpom.xml. 我是否缺少 pom.xml 中的一些依赖项?

持久性.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>

独立的.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>

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

4

8 回答 8

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 数据库”一章

这向您显示了您缺少的配置部分。

于 2012-11-02T00:38:48.480 回答
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

`

<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

`

希望这对某人有帮助!

于 2013-07-19T09:02:19.860 回答
1

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

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

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

C。在该文件夹中创建具有以下内容的 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>

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

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

我已经在 J​​Boss 7.1.1.Final 上测试过了

于 2012-10-31T13:18:31.027 回答
1

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

网页.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>

独立的.xml

<datasource jndi-name="java:jboss/datasources/OracleDS" pool-name="OracleDS" enabled="true" use-java-context="false">
于 2014-05-16T05:48:26.477 回答
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">
于 2014-06-21T08:06:28.220 回答
0

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

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

确保您在 module.xml 文件的开头没有空格,否则您将收到此驱动程序的“新缺少/不满足的依赖项”错误。

嗬!

于 2013-10-01T16:27:19.993 回答
0

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

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

希望这个对你有帮助,

谢谢。

于 2014-11-07T14:39:59.627 回答
0

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

于 2016-12-20T07:48:11.293 回答