我在Jboss 7服务器中配置了容器管理数据源(“myDataSource”)。数据源似乎正确部署(我从管理控制台检查) 我构建并部署了Spring示例webflow-primefaces-showcase应用程序到jboss,该演示已部署并正常工作。 我想在演示中使用jboss数据源,但我无法使用它。此时我没有任何可以访问数据库的支持代码,我只想正确配置数据源。
我为oracle驱动程序
添加了对pom.xml的依赖<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.1.0.7.0</version>
</dependency>
我创建了META-INF / persistence.xml
<persistence-unit name="myDataSource-emf" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/myDataSource</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" value="true"/>
<property name="hibernate.default_schema" value="schemaUserName"/>
</properties>
</persistence-unit>
将此添加到web.xml:
<persistence-unit-ref>
<persistence-unit-ref-name>persistence/myDataSource-emf</persistence-unit-ref-name>
<persistence-unit-name>myDataSource-emf</persistence-unit-name>
</persistence-unit-ref>
当我现在部署时,我得到:
"JBAS014771: Services with missing/unavailable dependencies" =>
"jboss.persistenceunit.\"webflow-primefaces-showcase-1.0.0-BUILD-SNAPSHOT.war#myDataSource-emf\
"jboss.naming.context.java.myDataSourceMissing
[jboss.persistenceunit.\"webflow-primefaces-showcase-1.0.0-BUILD-SNAPSHOT.war#myDataSource-emf\
"jboss.naming.context.java.myDataSource]"]}
某处我必须添加jndi参考:
<jee:jndi-lookup id="entityManager" jndi-name="java:comp/env/persistence/myDataSource-emf"
expected-type="javax.persistence.EntityManager"/>
但我不知道在哪里。我是否需要创建ApplicationContext.xml?我可以把它放在rootContext.xml中吗?
如何让这两个人在一起玩得很好?
我的配置:
答案 0 :(得分:0)
问题出在persistence.xml中 我更改了这一行:
<jta-data-source>java:/myDataSource</jta-data-source>
为:
<jta-data-source>java:jboss/datasources/myDataSource</jta-data-source>
我把jndi查找放在servlet-context.xml中:
<jee:jndi-lookup id="entityManagerFactory" jndi-name="java:comp/env/persistence/myDataSource-emf"
expected-type="javax.persistence.EntityManagerFactory"/>
编辑架构引用以添加jndi标记:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:faces="http://www.springframework.org/schema/faces"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">