2019年6月14日 | Leave a comment 问题: 下列代码不会调用 init 方法 @Component //@RequestScope @Scope(scopeName = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS) public class RequestOpContext implements InitializingBean { int i = 0; public RequestOpContext(){ System.out.println("RequestOpContext()"); } public void init(){ System.out.println("init"); i=10; } public int getId(){ return i; } @Override public void afterPropertiesSet() throws Exception { init(); } } 1234567891011121314151617181920212223 @Component//@RequestScope@Scope(scopeName = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)public class RequestOpContext implements InitializingBean { int i = 0; public RequestOpContext(){ System.out.println("RequestOpContext()"); } public void init(){ System.out.println("init"); i=10; } public int getId(){ return i; } @Override public void afterPropertiesSet() throws Exception { init(); }} 解决: