[英]Editing Persistence.xml jta-data-source from Weblogic deployment Plan.xml
我的应用程序使用带有Toplink Essentials JPA 2.1-60的Spring MVC 4.0.5,并已部署到Weblogic 10.3.6.0服务器。
我正在尝试部署我的应用程序的2个实例,以创建开发并测试部署。 这两个都将使用相同的.war文件。 这两个实例将具有不同的上下文根,并连接到不同的数据源。
这将在weblogic部署计划中定义。
我可以毫无问题地更改上下文根。 问题是试图更改数据源。
当我直接从Eclipse在服务器上运行时,数据源在weblogic.xml中定义。 但是,当我构建.war文件并手动部署应用程序时,数据源仅在persistence.xml中定义。 换句话说,我可以随意更改weblogic.xml,它不会影响它连接到的数据源。 我必须在persistence.xml中对其进行更改,以使其连接到其他数据源。
我无法从部署计划(plan.xml)中编辑persistence.xml,或者我的plan.xml只是错误的。
有没有一种方法可以强制persistence.xml引用weblogic.xml数据源,而不是硬编码的数据源? 据我所知,我可以使用部署计划来编辑weblogic.xml。 如果不是,是否有办法直接从部署计划中编辑persistence.xml数据源(从jdbc / PQRS更改为jdbs / PQRSTest)?
我不确定需要哪些文件来帮助,因此将包括所有这些文件。
谢谢你的帮助!
weblogic.xml
<!-- web application's server path for deployment -->
<weblogic-version>10.3.6</weblogic-version>
<context-root>pqrs</context-root>
...
<resource-description>
<res-ref-name>jdbc/PQRS</res-ref-name>
<jndi-name>jdbc/PQRS</jndi-name>
</resource-description>
persistence.xml
<persistence-unit name="pqrsPU" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<non-jta-data-source>jdbc/PQRS</non-jta-data-source>
...
<properties>
<property name="toplink.weaving" value="false"/>
<!-- <property name="toplink.logging.level" value="FINE"/> -->
</properties>
</persistence-unit>
web.xml
<web-app>
...
<resource-ref>
<description>My DataSource Reference</description>
<res-ref-name>jdbc/PQRS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
applicationContext.xml
<!-- Processes PersistenceUnit and PersistenceContext annotations for injection of JPA resources -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<!-- Creates a EntityManagerFactory for use with the JPA provider -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="pqrsPU"/>
<property name="dataSource" ref="dataSource" />
<!-- Needs spring instrument library along with aspectjrj.jar & aspectjweaver.jar libraries
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
-->
</bean>
plan.xml
<deployment-plan>
<application-name>crr</application-name>
<variable-definition>
<variable>
<name>contextRootName</name>
<value>/pqrsTest</value>
</variable>
<variable>
<name>dataSourceName</name>
<value>jdbc/PQRSTest</value>
</variable>
</variable-definition>
<module-override>
<module-name>pqrs.war</module-name>
<module-type>war</module-type>
<module-descriptor external="false">
<root-element>weblogic-web-app</root-element>
<uri>WEB-INF/weblogic.xml</uri>
<variable-assignment>
<name>contextRootName</name>
<xpath>/weblogic-web-app/context-root</xpath>
<operation>replace</operation>
</variable-assignment>
</module-descriptor>
<module-descriptor external="false">
<root-element>persistence</root-element>
<uri>WEB-INF/classes/META-INF/persistence.xml</uri>
<variable-assignment>
<name>dataSourceName</name>
<xpath>/persistence/persistence-unit[name="pqrsPU"]/non-jta-data-source</xpath>
<operation>replace</operation>
</variable-assignment>
</module-descriptor>
</module-override>
<config-root>/usr/local/oracle/wls103607/domains/Dpqrs/apps/test</config-root>
</deployment-plan>
如果在persistence.xml中使用java:comp / env / jdbc / myds样式的jndi名称,则必须在weblogic * xml中定义绑定
然后,您可以使用部署计划进行更改
(我自己尝试过)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.