我已經通過@Configuration和@Bean註釋看到了很多關於Spring配置的示例。但是我發佈了將@Bean註釋添加到直接調用來填充其他bean的方法是一種常見的做法。例如:爲什麼將@Bean添加到我將直接調用的方法中
@Bean
public Properties hibernateProperties() {
Properties hibernateProp = new Properties();
hibernateProp.put("hibernate.dialect",
"org.hibernate.dialect.H2Dialect");
hibernateProp.put("hibernate.hbm2ddl.auto", "create-drop");
hibernateProp.put("hibernate.format_sql", true);
hibernateProp.put("hibernate.use_sql_comments", true);
hibernateProp.put("hibernate.show_sql", true);
return hibernateProp;
}
@Bean public SessionFactory sessionFactory() {
return new LocalSessionFactoryBuilder(dataSource())
.scanPackages("com.ps.ents")
.addProperties(hibernateProperties())
.buildSessionFactory();}
所以,我想知道是否好轉只是宣佈hibernateProperties()私人沒有@Bean註解。
我想知道這是一個壞/不需要通常的做法或有背後的原因。
在此先感謝!
謝謝!我知道了。 –