Announcement Announcement Module
Collapse
No announcement yet.
@Configurable and @Transactional issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Configurable and @Transactional issue

    Hi, I am using Spring 3.0.5, Hibernate 3.6.0.Final, AspectJ 1.6.2

    There is an Aspect defined in config.xml as:
    <bean id="applicationContextInjectorAspect" class="com.x.aspect.ApplicationContextInjectorAspe ct" factory-method="aspectOf"/>

    ApplicationContextInjectorAspect have a object reference GenericDao as:
    @Aspect
    public class ApplicationContextInjectorAspect implements ApplicationContextAware {

    private Log logger = LogFactory.getLog(getClass());

    @PersistenceContext
    private EntityManager em;

    private ApplicationContext context;
    private GenericDao genericDao;
    ...
    }


    GenericDao is an interface and its implementaion object is as follows:
    @Configurable(autowire=Autowire.BY_NAME)
    public class GenericJpaDao implements GenericDao {
    Log logger = LogFactory.getLog(getClass());

    @PersistenceContext
    protected EntityManager em;

    public GenericJpaDao() {
    super();
    }

    @Transactional(readOnly=false)
    public void persist(Object entity) {
    em.persist(entity);
    }
    ...
    }


    When I try to run the integration tests, I get this error:
    org.springframework.beans.factory.UnsatisfiedDepen dencyException: Error creating bean with name 'applicationContextInjectorAspect' defined in class path resource [pm-service.xml]: Unsatisfied dependency expressed through bean property 'genericDao': : Error creating bean with name 'genericDao' defined in class path resource [pm-dao.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [com.x.dao.jpa.GenericJpaDao]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Post-processor tried to replace bean instance of type [com.x.dao.jpa.GenericJpaDao] with (proxy) object of type [$Proxy129] - not supported for aspect-configured classes!; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'genericDao' defined in class path resource [pm-dao.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [com.x.dao.jpa.GenericJpaDao]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Post-processor tried to replace bean instance of type [com.x.dao.jpa.GenericJpaDao] with (proxy) object of type [$Proxy129] - not supported for aspect-configured classes!

    Can someone plz help me? I am stuck with this issue for over a week now.
    Last edited by upgrade3; Feb 11th, 2011, 11:19 AM.

  • #2
    It could be that you're using the default implementation of the @Transactional annotation, i.e. Spring AOP proxies, which is known not to be compatible with @Configurable. Try changing this line in your Spring config file

    Code:
    <tx:annotation-driven ...
    to this:

    Code:
    <tx:annotation-driven mode="aspectj" ...
    You also need to enable AspectJ weaving; the easiest way is at compile time using the Maven plugin.

    Comment


    • #3
      Thankyou for your response.

      I tried changing the
      <tx:annotation-driven transaction-manager="transactionManager" /> to
      <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />

      And I am doing Aspect weaving at compile time using maven aspect plugin:
      <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>aspectj-maven-plugin</artifactId>
      <version>1.1</version>
      <configuration>
      <source>1.5</source>
      <target>1.5</target>
      <XnoInline>true</XnoInline>
      <aspectDirectory>src/main/java</aspectDirectory>
      <testAspectDiectory>
      src/main/test
      </testAspectDiectory>
      <weaveMainSourceFolder>true</weaveMainSourceFolder>
      <aspectLibraries>
      <aspectLibrary>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      </aspectLibrary>
      </aspectLibraries>
      </configuration>
      <executions>
      <execution>
      <id>compile</id>
      <goals>
      <goal>compile</goal>
      </goals>
      </execution>
      <execution>
      <id>test-compile</id>
      <goals>
      <goal>test-compile</goal>
      </goals>
      </execution>
      </executions>
      </plugin>


      I do mvn install on command prompt and try running the integration tests in Eclipse and still get the same error.

      Comment


      • #4
        Hi, I'm also stuch for a long time with the same problem.

        Is it a way to have the @Configurable handled by AspectJ and the @Transactional by Spring proxy in the same class or does this definitely not work (either with LTW or compile time weaving)?

        I would really prefer not have @Transactional handled by AspectJ and use compile time weaving.

        Thanks for your help.

        Comment


        • #5
          Originally posted by pwanner View Post
          Is it a way to have the @Configurable handled by AspectJ and the @Transactional by Spring proxy in the same class or does this definitely not work (either with LTW or compile time weaving)?
          This post by AOP guru Adrian Colyer tells you how (using load-time weaving):

          http://forum.springframework.org/sho...37&postcount=2

          Comment


          • #6
            Thank you for your answer Andrew,

            Event with the AnnotationBeanConfigurerAspect declared in the aop.xml I still get the "java.lang.IllegalStateException: Post-processor tried to replace bean instance of type... ...not supported for aspect-configured classes!" exception.

            It looks like once a class has been woven by AspectJ, Spring cannot proxy it anymore.

            Does it really work for the two annotations (@Configurable and @Transactional) in the same class?

            BTW is it way for compile time weaving?
            Last edited by pwanner; Feb 17th, 2011, 03:40 AM.

            Comment

            Working...
            X