简体   繁体   English

从Weblogic部署Plan.xml编辑Persistence.xml jta-data-source

[英]Editing Persistence.xml jta-data-source from Weblogic deployment Plan.xml

My application is using Spring MVC 4.0.5 with Toplink Essentials JPA 2.1-60 and is deployed to a Weblogic 10.3.6.0 server. 我的应用程序使用带有Toplink Essentials JPA 2.1-60的Spring MVC 4.0.5,并已部署到Weblogic 10.3.6.0服务器。

I'm trying to deploy 2 instances of my application in order to create a development as well as testing deployments. 我正在尝试部署我的应用程序的2个实例,以创建开发并测试部署。 Both of these will use the same .war file. 这两个都将使用相同的.war文件。 The two instances will have different context-roots as well as connect to different data sources. 这两个实例将具有不同的上下文根,并连接到不同的数据源。

This will be defined in a weblogic deployment plan. 这将在weblogic部署计划中定义。

I'm able to change the context-root without any issue. 我可以毫无问题地更改上下文根。 The problem is trying to change the data source. 问题是试图更改数据源。

When I run on server directly from Eclipse, the data source is defined within weblogic.xml. 当我直接从Eclipse在服务器上运行时,数据源在weblogic.xml中定义。 But when I build the .war file and manually deploy the application, the data source is only defined within persistence.xml. 但是,当我构建.war文件并手动部署应用程序时,数据源仅在persistence.xml中定义。 In other words, I can change weblogic.xml all I want and it doesn't affect the which data source it connects to. 换句话说,我可以随意更改weblogic.xml,它不会影响它连接到的数据源。 I have to change it in persistence.xml for it to connect to the other data source. 我必须在persistence.xml中对其进行更改,以使其连接到其他数据源。

Either I can't edit persistence.xml from my deployment plan (plan.xml) or my plan.xml is just wrong. 我无法从部署计划(plan.xml)中编辑persistence.xml,或者我的plan.xml只是错误的。

Is there a way to force the persistence.xml to refer to the weblogic.xml data source instead of the hard coded one? 有没有一种方法可以强制persistence.xml引用weblogic.xml数据源,而不是硬编码的数据源? Since I know I can edit weblogic.xml using the deployment plan. 据我所知,我可以使用部署计划来编辑weblogic.xml。 If not, is there a way to edit the persistence.xml data source directly from the deployment plan (change from jdbc/PQRS to jdbs/PQRSTest)? 如果不是,是否有办法直接从部署计划中编辑persistence.xml数据源(从jdbc / PQRS更改为jdbs / PQRSTest)?

I'm not sure which files are needed to help, so I'm going to include all of them. 我不确定需要哪些文件来帮助,因此将包括所有这些文件。

Thanks for your help! 谢谢你的帮助!

weblogic.xml 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.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.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 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 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>

if you use java:comp/env/jdbc/myds style of jndi name in persistence.xml you ll have to define binding in weblogic*xml 如果在persistence.xml中使用java:comp / env / jdbc / myds样式的jndi名称,则必须在weblogic * xml中定义绑定

then those, you could change it using deployment plan 然后,您可以使用部署计划进行更改

(havent tried it yet myself) (我自己尝试过)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM