开发者

Spring - setter injection method modifier

Totally basic question, but what type of modifier is allowed for doing Spring setter injection. I am using Spring Proxy AOP and notice that only public methods are proxied and so thought about switching my setters m开发者_StackOverflow中文版ethods in my classes to protected/package...would setter injection still work? I couldn't find anything in the docs about the modifier type.


For beans configured via XML I think the setter methods have to be public. By default Spring AOP uses dynamic proxies which only applies to methods defined as part of interfaces. So by not including the setter methods in the interface you can exclude them from AOP.


  • I am using Spring Proxy AOP and notice that only public methods are proxied

from Spring Documentation:

"Due to the proxy-based nature of Spring's AOP framework, protected methods are by definition not intercepted, neither for JDK proxies (where this isn't applicable) nor for CGLIB proxies (where this is technically possible but not recommendable for AOP purposes). As a consequence, any given pointcut will be matched against public methods only!"

"If your interception needs include protected/private methods or even constructors, consider the use of Spring-driven native AspectJ weaving instead of Spring's proxy-based AOP framework. This constitutes a different mode of AOP usage with different characteristics, so be sure to make yourself familiar with weaving first before making a decision."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜