gpt4 book ai didi

jpa - 错误新的缺失/不满足的依赖项 : (Cannot configure datasource)

转载 作者:行者123 更新时间:2023-12-01 13:07:27 24 4
gpt4 key购买 nike

我有一个使用 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>

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

谁能告诉我我做错了什么?

最佳答案

您是否启用了 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 数据库”一章

向您显示您缺少配置的哪一部分。

关于jpa - 错误新的缺失/不满足的依赖项 : (Cannot configure datasource),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13158387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com