1

Spring MVC Webアプリ(Spring Framework 3.0.5)を作成しようとしています。IntelliJ IDEA 11.1.3を使用して、WebLogic Server(10.3.4)にアプリをデプロイしています。私のWebページの1つが、JPAを使用してデータベースにデータを保存しようとしています。私のpersistence.xmlは以下を指定します:

<?xml version="1.0" encoding="UTF-8"?>
<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="LeaveSchedulerJPA" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.engilitycorp.leavetracker.jpa.UserRole</class>
    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:xe "/>
        <property name="javax.persistence.jdbc.user" value="leavescheduler"/>
        <property name="javax.persistence.jdbc.password" value="xxx"/>
        <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
    </properties>
    </persistence-unit>
</persistence>

ただし、デバッガーを見ると、EntityManagerFactoryがとして表示され、org.apache.openjpa.persistence.EntityManagerFactoryImplを呼び出すとcreateEntityManagerorg.apache.openjpa.persistenceArgumentException「JDBCドライバーまたはDataSourceクラス名をConnectionDriverNameプロパティで指定する必要があります」というメッセージが表示されます。

私の初心者の目には、persistence.xmlが処理されていないように見えます。私はそれを入れてみましたが(project)/src/main/resources/META-INF(project)/src/main/resources/META-INF/spring同じ不幸な結果になりました。

私はHibernateの永続性を使用することを約束していません。ただし、JPA 2を実装するものを使用したいので、環境を構成するのに非常に苦労しています。たとえば、openjpaがどのようにアプリに関与したのかはほとんどわかりません。何か(WebLogic?、IntelliJ IDEA?)のデフォルトのJPAプロバイダーである可能性があると思います。どんな助け/提案も大歓迎です。

私のweb.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

root-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
</beans>

サーブレット-コンテキスト.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        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">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:component-scan base-package="com.engilitycorp.leavetracker" />

</beans:beans>
4

3 に答える 3

2

WebLogic10.3.4はJavaEE5に準拠しており、JPA 1.0実装(OpenJPAおよびTopLink)とともに出荷されます。

WebLogicのドキュメント(http://docs.oracle.com/cd/E17904_01/web.1111/e13720/using_toplink.htm#CIHDJHHI)によると、JPA 2.0でも使用できますが、パッチを適用した後でのみ使用できます。指示に従うだけです(パッチ適用は非常に簡単なようですが、テストはしていません)。

user1654209が最初の回答で書いたように、おそらくパッチを適用せずに独自のJPA2.0プロバイダーを使用することもできます。ただし、WebLogicで提供されるJPA 1.0クラスは、上位レベルのクラスローダーによってロードされ、WARファイルにパッケージ化されたクラスよりも優先されるため、邪魔になる可能性があります。このような動作を防ぐには、次の2つのオプションがあります。

  • アプリケーションのWARを、次の行を含むファイルを含むEARアーカイブ内にパックします(標準ファイルMETA-INF/weblogic-application.xmlも含める必要があります)。META-INF/application.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <weblogic-application xmlns="http://xmlns.oracle.com/weblogic/weblogic-application/1.0/weblogic-application.xsd">
      <prefer-application-packages>
        <package-name>javax.persistence.*</package-name>
      </prefer-application-packages>
    </weblogic-application>
    
  • 次の行を使用して、WARアーカイブにファイルを追加WEB-INF/weblogic.xmlします。

    <?xml version='1.0' encoding='UTF-8'?>
    <weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
    
      <container-descriptor>
        <prefer-web-inf-classes>true</prefer-web-inf-classes>
      </container-descriptor>
    </weblogic-web-app>
    
于 2012-10-25T22:46:31.443 に答える
1

context.xmlでentityManagerFactoryBeanを構成する必要があります。これは、JPAプロバイダーとしてeclipselinkを使用する例です。

<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        id="dataSource">
        <property name="driverClassName" value="${database.driverClassName}" />
        <property name="url" value="${database.url}" />
        <property name="username" value="${database.username}" />
        <property name="password" value="${database.password}" />
    </bean>

    <bean
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        id="entityManagerFactory">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean id="jpaAdapter"
                class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
            </bean>
        </property>
    </bean>
于 2012-10-22T09:56:37.780 に答える
0

プロバイダーを設定するだけでは不十分です。jdbc url、ユーザー名、パスワードなどのデータベース接続データを設定する必要があります。設定しましたか?前述のように、jdbcクラス名も設定する必要があり、jdbcドライバーがクラスパスに含まれている必要があります。

これをコンテナで実行していて、weblogicでデータソースを設定する場合は、休止状態のcfgからjndiデータソースを参照するだけですが、weblogicコンソールに入力して、そこにデータソースと接続プールを作成する必要があります。

persistence.xmlでJNDI名を設定する方法については、休止状態のドキュメントを参照してください

于 2012-10-18T01:27:47.837 に答える