我想在运行时加载数据库值,当spring应用程序启动时。
public List<MyBean> beanValues() {
List<MyBean> value; // fetch all values from database
}
使用春豆。这样当应用程序启动时数据就会被加载
@Configuration
class BeanList {
@Bean
public List<MyBean> beanValues() {
/*
List<MyBean> result = dao.getAllBeans(); // use your dao to fetch all
// values from database and store it in a variable
*/
}
}
// now to access the values use Autowired annotation
@Component
class MyApp {
@Autowired
private List<MyBean> beanValues;
}