Weblogic10.x部署Spring3、Spring Data JPA

项目中使用了Spring3、Spring Data JPA在开发过程中使用Jetty或Tomcat上没有任何问题,部署在Weblogic10.x上时各种错,目前使用这种组合的项目不在于少数,特此记录一下。
Weblogic10.x只支持JPA1.X,不支持JPA2.X,内置的JPA接口与项目中的Hibernate的hibernate-jpa-2.0-api-1.0.1.Final.jar有冲突,无法部署启动项目,还有就是Weblogic内置的一些版本比较老的jar与项目中使用的也有冲突,道理是一样的,OK,开始!
一、更改persistence.xml名称
我们不想在部署时让Weblogic自动加载persistence.xml文件,所以必须要重命名,比如mps-persistence.xml,然后修改Spring配置文件
<!--WizRtf2Html Charset=0 --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceXmlLocation" value="classpath:META-INF/mps-persistence.xml" />
        <property name="dataSource" ref="dataSource" />
        <property name="persistenceUnitName" value="mps" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="database" value="DB2" />
            </bean>
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">${db.mps.dialect}</prop>
                <prop key="hibernate.format_sql">${db.mps.formatSql}</prop>
                <prop key="hibernate.hbm2ddl.auto">${db.mps.ddlAuto}</prop>
            </props>
        </property>
    </bean>
注意:
 <property name="persistenceXmlLocation" value="classpath:META-INF/mps-persistence.xml" />
此处改为你重命名的文件名称;
二、打ear包
修改好上面的配置文件后,发布还是有问题的,需要把war打成ear包,新建ear工程,然后编写weblogic-application.xml描述文件:
<!--WizRtf2Html Charset=0 --> <?xml version="1.0" encoding="UTF-8"?>
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
    <prefer-application-packages>
        <package-name>antlr.*</package-name>
        <package-name>org.apache.commons.*</package-name>
        <package-name>org.apache.xmlbeans.*</package-name>
        <package-name>org.springframework.*</package-name>
        <package-name>org.hibernate.*</package-name>
        <package-name>javax.persistence.*</package-name>
        <package-name>org.apache.log4j.*</package-name>
    </prefer-application-packages>
</weblogic-application>
文件必须打包后必须放在ear根目录下的META-INF文件夹中,与application.xml在同一个文件夹
三、部署ear致Weblogc控制台即可
四、备注
maven ear打包插件
<!--WizRtf2Html Charset=0 --> <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <finalName>${project.artifactId}</finalName>
                    <version>5</version>
                    <generatedDescriptorLocation>${basedir}/src/main/application/META-INF</generatedDescriptorLocation>
                    <modules>
                        <webModule>
                            <groupId>com.demo</groupId>
                            <artifactId>xxx</artifactId>
                            <uri>xxx.war</uri>
                            <bundleFileName>xxx.war</bundleFileName>
                            <contextRoot>/xxx</contextRoot>
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
ear打包命令:ear:ear
ear生成application.xml命令:ear:generate-application-xml
ear项目结构图:
Weblogic10.x部署Spring3、Spring Data JPA
 

 

你可能感兴趣的:(weblogic)