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

  • spring data jpa and cxf dynamic proxy

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

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""
         <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 id="aipDataSource" class="com.locator.C3P0DataSourceFactoryBean" depends-on="aiplocatorbean"> 
    		<property name="locatorDao" ref="aiplocatorbean"/>
    		<property name="connectionPoolName" value="ETSAIPDB_DATASOURCE"/>
          <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 id="aipTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="aipEntityManagerFactory" />
                    <property name="dataSource" ref="aipDataSource"  />
            <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:
    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
                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.


  • #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...


    • #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.



      • #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.