How do I configure dynamic weaving using EclipseLink & Spring?
For weaving with Spring I believe you need something like,
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"> <property name="defaultDataSource" ref="dataSource" /> <property name="dataSources"> <map> <entry> <key> <value>jdbc/__default</value> </key> <ref bean="dataSource" /> </entry> <entry> <key> <value>jdbc/jta</value> </key> <ref bean="dataSource" /> </entry> </map> </property> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /> </property></bean>
There is some information here,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/JPASpring
Ensure you are not accessing your classes before accessing the Spring context.
Another solution is to use static weaving.
Now, I am also using EclipseLink 2.2
and Spring 3.1
as below. My configuration is a little different with yours.There is no loadTimeWeaver
configuration in your eclipseLinkEntityManagerFactory
. I think, it will be ok if you use as below.
Please, try as below with your Oracle DB
information..
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:faces="http://www.springframework.org/schema/faces" xmlns:int-security="http://www.springframework.org/schema/integration/security" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:sec="http://www.springframework.org/schema/security" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/integration/security http://www.springframework.org/schema/integration/security/spring-integration-security-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <context:annotation-config/> <context:component-scan base-package="your-package"/> <tx:annotation-driven transaction-manager="transactionManager" /> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="your-driver"/> <property name="url" value="your-database-url"/> <property name="username" value="your-username"/> <property name="password" value="your-passowrd"/> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"><!-- <property name="dataSource" ref="dataSource"/>--> <property name="persistenceUnitName" value="your-persistence-unit-name"/> <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/> <property name="jpaDialect"> <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect"/> </property> <property name="jpaPropertyMap"> <props> <prop key="eclipselink.weaving">false</prop> </props> </property> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"> </bean> </property> </bean> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"> <property name="databasePlatform" value="org.eclipse.persistence.platform.database.OraclePlatform" /> <property name="generateDdl" value="false"/> <property name="showSql" value="true"/> </bean></beans>
copy org.springframework.instrument-3.1.0.M2.jar
into tomcat/lib
directory and try it again.