错误数据源配置的弹簧示例
问题描述:
我尝试运行jboss-springmvc-webapp的示例项目,但未能配置数据源。错误数据源配置的弹簧示例
的错误是:
JBAS014775: New missing/unsatisfied dependencies:
service jboss.jdbc-driver.mysql (missing) dependents: [service jboss.data-source.jboss/datasources/SpringQuickstartDS]
我的persistence.xml是:
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="primary">
<!-- If you are running in a production environment, add a managed
data source, this example data source is just for development and testing! -->
<!-- The datasource is deployed as WEB-INF/spring-quickstart-ds.xml, you
can find it in the source at src/main/webapp/WEB-INF/spring-quickstart-ds.xml -->
<jta-data-source>java:jboss/datasources/SpringQuickstartDS</jta-data-source>
<properties>
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/spring-quickstart/persistence" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
我datasource.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
<!-- The datasource is bound into JNDI at this location. We reference
this in META-INF/persistence.xml -->
<datasource jndi-name="java:jboss/datasources/SpringQuickstartDS"
pool-name="kitchensink-quickstart" enabled="true"
use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/testdb</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password></password>
</security>
</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>
答
如果您使用的jboss-用SpringMVC-web应用architype,那么它应该配置为使用H2作为数据源。我会首先回到该配置以确认它的工作原理。
然后,当你知道其他所有工作正常时,你可以设置一个MySQL数据源。有两件事你需要知道。您一次只能指向一个数据源,因此您必须从上述文件中删除其他数据源。它只能拥有MySQL信息(如果这是你使用的数据源)。其次,您需要确保您有要使用的数据库的JDBC驱动程序。
每个版本的JBoss都有很好的文档来设置它。你使用的是什么版本的JBoss,我会发布文档页面?
也可以通过https://zorq.net/b/2011/07/12/adding-a-mysql-datasource-to-jboss-as-7/解决 – user504909 2013-05-06 22:43:40