2012-08-10 29 views
1

我有一個在Jboss 7服務器中配置的容器託管數據源(「myDataSource」)。數據源似乎正確部署(我從管理控制檯中檢查它)。
我構建並部署了Spring示例webflow-primefaces-showcase應用程序到jboss,演示部署並正常工作。 我想在演示中使用jboss數據源,但我無法使其工作。在這一點上,我沒有任何可以訪問數據庫的後臺代碼,我只想正確配置數據源。配置Spring Web Flow演示應用程序以使用JBoss 7託管數據源

我添加了一個依賴於pom.xml中爲Oracle驅動程序

<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

回答

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"> 
相關問題