简体   繁体   中英

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.

I'm trying to deploy 2 instances of my application in order to create a development as well as testing deployments. Both of these will use the same .war file. 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.

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. But when I build the .war file and manually deploy the application, the data source is only defined within 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. I have to change it in persistence.xml for it to connect to the other data source.

Either I can't edit persistence.xml from my deployment plan (plan.xml) or my plan.xml is just wrong.

Is there a way to force the persistence.xml to refer to the weblogic.xml data source instead of the hard coded one? Since I know I can edit weblogic.xml using the deployment plan. 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)?

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

<!-- 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>

if you use java:comp/env/jdbc/myds style of jndi name in persistence.xml you ll have to define binding in weblogic*xml

then those, you could change it using deployment plan

(havent tried it yet myself)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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