1

我在 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 中吗?

如何让这两个一起玩得很好?

我的配置:

  • JBoss 7.1
  • 春天 3.1.2
  • Spring Web Flow 2.3.1
4

1 回答 1

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">
于 2012-08-13T22:00:33.610 回答