@Configuration public class AppConfig { @Bean(initMethod = "init") public Foo foo() { return new Foo(); } @Bean(destroyMethod = "cleanup") public Bar bar() { return new Bar(); } } 上述代码中initMethod和destroyMethod后面没有括号. 记住千万不要带括号.…
Person类: public class Person { private int i = 0; public Person(){ System.out.println("实例化一个对象"); } public void init(){ System.out.println("调用初始化方法...."); } publi…
In Spring, you can use init-method and destroy-method as attribute in bean configuration file for bean to perform certain actions upon initialization and destruction. Alternative to InitializingBean and DisposableBean interface. Example Here's an exa…
在实际的开发中,有的bean中会有集合属性,如下: package com.sevenhu.domain; import java.util.List; /** * Created by hu on 2016/3/31. */ public class RichMen { private List<Car> cars; public void setCars(List<Car> cars) { this.cars = cars; } } 那么集合属性的配置如下: <bean…