JavaConfig: Replacing aop:advisor and tx:advice

后端 未结 2 2073
野趣味
野趣味 2021-01-31 00:58

I\'m wondering if I can map this piece of xml-configuration to Spring JavaConfig:




        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-31 01:01

    Currently it isn't possible to translate all XML-based AspectJ settings to a Java based configuration. Probably it will never be. The main reason is that Java doesn't support method literals. But there is a workaround, which was first presented here: https://jira.springsource.org/browse/SPR-8148

    1. Continue using by including the relevant XML snippet using @ImportResource
    2. Convert any existing elements to use @Aspect style.

    Referring to the documentation, I would say that you're already nearly done with your configuration you have described above. You just have to change you config like this:

    
         
    
    

    Leave the rest like it is and import that resource:

    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Pointcut;
    
    @Aspect
    @ImportResource("classpath:/aop-config.xml")
    public class AspectConfig
    {
        @Pointcut("@within(org.springframework.stereotype.Service)")
        public void serviceAnnotatedClass() {}
    }
    

    I hope I could help...

提交回复
热议问题