Announcement Announcement Module
Collapse
No announcement yet.
spring data jpa and cxf dynamic proxy Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring data jpa and cxf dynamic proxy

    i have the following setup for aip-persistence-context file:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:tx="http://www.springframework.org/schema/tx" 
    	xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="
              http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
              http://www.springframework.org/schema/data/jpa  http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
         <bean id="aiplocatorbean" class="com.locator.service.S2LocatorServiceBean">
            <property name="logicalDbName" value="ETS_AIPDB"></property>
            <property name="sourceHostName" value="DOMAIN1"></property>
            <property name="logicalServerName" value="USDTP6"></property>
        </bean>
    
        <bean id="aipDataSource" class="com.locator.C3P0DataSourceFactoryBean" depends-on="aiplocatorbean"> 
    		<property name="locatorDao" ref="aiplocatorbean"/>
    		<property name="connectionPoolName" value="ETSAIPDB_DATASOURCE"/>
         </bean>
    
    
    
          <bean id="aipEntityManagerFactory"    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="persistenceXmlLocation" value="META-INF/aip-persistence-unit.xml" />
    		<property name="persistenceUnitName" value="aipPerUnit" />
            <property name="dataSource" ref="aipDataSource"/>
    
            <property name="jpaVendorAdapter">
    	      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    		      <property name="showSql" value="true" />
    		      <property name="generateDdl" value="false" />
    		      <property name="databasePlatform" value="org.hibernate.dialect.OracleDialect" />
    	      </bean>
    	  </property>
    		  
    	</bean>
    	
            <bean id="aipTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="aipEntityManagerFactory" />
                    <property name="dataSource" ref="aipDataSource"  />
    	</bean>
    
            <jpa:repositories base-package="com.service.aip.impl.persistence.jpa" transaction-manager- ref="aipTransactionManager" />
    
        <tx:annotation-driven transaction-manager="aipTransactionManager" />
    where the S2ServiceLocatorBean is a spring bean that uses an annotation (managed by a cxf dynamic proxy called jaxwsclientproxy) to call a service to return a datasource. code fragment below:
    Code:
    public class S2ServiceLocatorBean 
    {
                // this is the jaxws client proxy created to call the service
                // the annotation is processed using a BeanAnnotationPostProcessor and 
               // we use afterPropertiesSet and use Spring's ReflectionServiceFactoryBean to get the
               // SEI (service endpoint interface ) to make a SOAP call to get the DB Info
                @ServiceProxy(channel="locator")
                LocatorDBInfoSvc locatorService;
    
                public DBInfo getLocatorInfo()
                {
                    LocatorGetDbInfoResponseT response = locatorService.submitLocatorGetDbInfo(input);
                    return new DBInfo(response);
                 }
    }
    the problem is when i use jpa:repositories along with EMF (entity manager factory) the line locatorService.submitLocatorGetDbInfo always throws NPE (Null Pointer Exception).

    it's as if once spring-data-jpa is done with making proxy objects it won't allow the ServiceProxy beanannotationpost processor to do it's job.

    any clues to why this happens as i find it quite interesting.
    note : i also implemented the SmartLifeCycle on S2ServiceLocatorBean so it would be the first bean that's instatiated or destroyed....this also doesn't help.

    regards,
    -cogitate

  • #2
    some "progress".
    [1] the datasource gets the connection string to inject using a proxy object - which calls a service to get the string. the proxy itself uses BeanPostProcessor (in particular AnnotationBeanPostProcessor).
    [2] as part of loading jpa:repositories spring renders all beanpostproccessors that are tied to the jpa repository in-eligible for proxying mechanism. thus, it doesn't give a chance for the datasource to be formed (as beanpostprocessors are shady area where the beans are still in construction).
    [3] so, need a way to load the dataSource bean before jpa:repositories scanner does it's job ( and then it can make it in-eligible for beanpostprocessor processing).
    [4] what i tried is changing the order of imports and adding depends-on for loading the bean first...all to no avail...

    Comment


    • #3
      i worked around this issue by loading another spring context using generic application context and calling the proxy directly instead of "injecting" it using BPP ( bean post processors )

      i hope to know why it doesn't work (details) some day.

      regards,
      -cogitate

      Comment


      • #4
        I love to be here and I would like to ask if you know Masonry contractors in Washington DC? it's my pleasure if you could share me something.

        Comment

        Working...
        X