注意@Bean中的initMethod和destroyMethod

@Configuration
public class AppConfig {
@Bean(initMethod = "init")
public Foo foo() {
return new Foo();
}
@Bean(destroyMethod = "cleanup")
public Bar bar() {
return new Bar();
}
}

上述代码中initMethod和destroyMethod后面没有括号。

记住千万不要带括号。

原文地址:https://www.cnblogs.com/1540340840qls/p/7931816.html