0
因此,何時執行@configuration類,它的範圍是什麼?何時執行spring @ configuration類?
這是每個會話一個嗎?每個應用程序一個?但是我的下一個問題是執行後bean返回到哪裏?也許這段代碼會幫助你更好地理解我的意思。
@Configuration
@PropertySource("classpath:application.properties")
public class AppConfig {
@Autowired
Environment env;
@Bean
public DBConnection testBean() {
DBConnection testBean = new DBConnection();
testBean.setName(env.getProperty("testbean.name"));
return testBean;
}
}
那麼這個DBConnection何時或多或少會有效/啓動?
我建議你在春季瞭解Bean的生命週期。 Spring參考:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html或者這個:http://javabeginnerstutorial.com/spring-framework-tutorial/java-spring -bean生命週期/ – jny