[英]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.