Spring AOP at Service Layer

后端 未结 2 688
滥情空心
滥情空心 2020-12-29 13:07

I need some help with Spring AOP. I\'ve the following code:


@Service
public class UserSecurityService implements UserDetailsService {

    @Autowired
          


        
2条回答
  •  抹茶落季
    2020-12-29 13:42

    You are not injecting an interface so you need to use CGLIB proxies, the spring reference manual states:

    Spring AOP defaults to using standard J2SE dynamic proxies for AOP proxies. This enables any interface (or set of interfaces) to be proxied.

    Spring AOP can also use CGLIB proxies. This is necessary to proxy classes, rather than interfaces. CGLIB is used by default if a business object does not implement an interface. As it is good practice to program to interfaces rather than classes, business classes normally will implement one or more business interfaces.

    Spring has decided to use a J2SE proxy (com.sun.proxy.$Proxy57) probably because CrudService implements an interface. To force the use of CGLIB you can tweak your XML:

    
    

提交回复
热议问题