WebLogic JPA Spring integration configuration¶
This page details the configuration for integrating Spring Data JPA with an [[Oracle]] database within a [[WebLogic]] server environment. It covers the XML-based bean definitions required for the Entity Manager, Transaction Management, and Data Source, as well as the configuration for remote EJB lookups.
Configuration Overview¶
The integration is primarily configured through the Spring application context (e.g., applicationContext.xml). This involves defining the data source, the JPA EntityManagerFactory, the transaction manager, and repository scanning.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]
1. Component Scanning¶
Spring is configured to automatically detect and register components (such as Models and Services) within specific base packages.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]
<context:component-scan base-package="core.*.model , lott.*.model"></context:component-scan>
2. Data Source Configuration¶
A DriverManagerDataSource is configured to connect to an Oracle database.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]
- Driver:
oracle.jdbc.OracleDriver - URL: JDBC connection string pointing to the host and service name (e.g.,
jdbc:oracle:thin:@DB.PF2DEV1-OOB.COM:1521/UB8.pf2dev1.com)
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="username" value="core"></property>
<property name="password" value="core"></property>
<property name="driverClassName" value="oracle.jdbc.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@DB.PF2DEV1-OOB.COM:1521/UB8.pf2dev1.com"></property>
</bean>
3. JPA EntityManagerFactory¶
The LocalContainerEntityManagerFactoryBean is configured to manage JPA entities.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]
Key configurations include:
* LoadTimeWeaver: Uses InstrumentationLoadTimeWeaver for JPA class instrumentation.
* JPA Vendor Adapter: Configured for [[Hibernate]] as the provider.
* Database dialect: Oracle10gDialect
* SQL logging: Enabled (show_sql and format_sql)
* Packages to Scan: Specifies the Java packages containing the JPA entities (e.g., core.*, lott.*).
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="ORACLE"/>
<property name="generateDdl" value="false"/>
<property name="showSql" value="true"/>
</bean>
</property>
<property name="packagesToScan">
<list>
<value>core.*</value>
<value>lott.*</value>
</list>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">none</prop>
</props>
</property>
</bean>
4. Transaction Management¶
Transaction management is handled by the JpaTransactionManager, which is bound to the EntityManagerFactory.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md] Annotation-driven transactions are enabled to support the @Transactional annotation.
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
5. Spring Data Repositories¶
Spring Data JPA repositories are enabled by scanning specific persistence packages.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]
<jpa:repositories base-package="core.*.persistence , lott.*.persistence"
entity-manager-factory-ref="entityManagerFactory">
</jpa:repositories>
WebLogic JNDI Configuration¶
The configuration also supports looking up remote EJBs hosted on the WebLogic Server via JNDI.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]
JNDI Environment¶
The JNDI environment properties define the connection details for the WebLogic Server:
* Initial Context Factory: weblogic.jndi.WLInitialContextFactory
* Provider URL: t3://localhost:8080
* Credentials: WebLogic username and password.
<beans:properties id="jndiEnvironment">
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">t3://localhost:8080</prop>
<prop key="java.naming.security.principal">weblogic</prop>
<prop key="java.naming.security.credentials">1qaz2wsx</prop>
</beans:properties>
Remote EJB Lookup¶
JndiObjectFactoryBean is used to retrieve a remote service bean.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]
<bean id="casualGameLottGroupSeriesServiceRemote" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="bpm.ejb.CasualGameLottGroupSeriesService#core.bpm.service.settings.CasualGameLottGroupSeriesServiceRemote"></property>
<property name="jndiEnvironment" ref="jndiEnvironment" />
</bean>
Related Concepts¶
- Spring Data JPA
- [[WebLogic]]
- JNDI
- [[Hibernate]]
- [[Oracle]]
Sources¶
^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]