Announcement Announcement Module
Collapse
No announcement yet.
How to exclude bean from autoproxying? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to exclude bean from autoproxying?

    Hi,

    I'd like to know if there's any simple way to exclude a particular bean from being auto-proxied by Spring. My spring context has a <tx:annotation-driven ../> declaration, which I suspect is causing all beans to be wrapped with proxies.

    The reason I need this is that my data source bean relies in a 'factory method' bean that decrypts the user password. However this bean can't be instantiated because it depends(it seems internally) on the transaction interceptor, which depends on the JPA entity manager that depends on the data source, so it ends up in a circular dependency.


    Code:
        
    <!-- the datasource -->
    <bean id="dataSource"
          class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
          <property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver" />
          <property name="jdbcUrl" value="jdbc:jtds:sybase://${db.server}:${db.port}/${db.database}" />
          <property name="user" value="${db.username}" />
          <property name="password">
    		<bean factory-bean="encryptedStringFactory" factory-method="decrypt">
    			<constructor-arg value="${db.password}"/>
    		</bean>
    	  </property>      
       </bean> 
    ...
     	<bean id="encryptedStringFactory" class="com....EncryptedStringFactory" autowire="no">
    		<property name="decryptor">  
    			<bean class="com....Decryptor" >
    				 <property name="key" value="${user.home}/.key-properties" />
    			</bean>
    		</property>
    	</bean>
    ...
    <tx:annotation-driven transaction-manager="transactionManager" />
    The exception reported is:
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot create inner bean 'encryptedStringFactory$created#351f6d' while setting bean property 'password'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'encryptedStringFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot create inner bean 'com....util.Decryptor#1a2335d' of type [com.....util.Decryptor] while setting bean property 'decryptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.....util.Decryptor#1a2335d' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Unsatisfied dependency expressed through bean property 'jpaDialect': Set this property value or disable dependency checking for this bean.
    Thanks.

    Julio

  • #2
    Hi Julio,
    Although I am not sure but you can try by defining a bean like this:-


    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <aop:config>
    <aopointcut id="serviceMethods" expression="execution(* <Your class name with full package>.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods" /> </aop:config>
    </bean>

    <tx:advice id="txAdvice" transaction-manager="transactionManager" > <tx:attributes> <tx:method name="*" propagation="REQUIRES_NEW" /> </tx:attributes> </tx:advice>

    Comment


    • #3
      I don't see a circular reference in your exception trace but unsatisfied dependency...

      Code:
      nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Unsatisfied dependency expressed through bean property 'jpaDialect': Set this property value or disable dependency checking for this bean.

      Comment

      Working...
      X