如何在一个网站初始化的servlet中使用spring容器中的bean
1个回答
展开全部
1
2
3
4
5
6
7
8
9
10
11
12
13
String[] contextConfigurations = {
"classpath:/spring/*-datasource.xml",
"classpath:/spring/*-dao.xml",
"classpath:/spring/*-service.xml",
"classpath:/spring/consumer.xml" };
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(contextConfigurations);
/*
String[] beans = context.getBeanDefinitionNames();
for(String bean : beans) {
System.out.println(bean);
}*/
workMainService = (WorkMainService)context.getBean("workMainServiceImpl");
2
3
4
5
6
7
8
9
10
11
12
13
String[] contextConfigurations = {
"classpath:/spring/*-datasource.xml",
"classpath:/spring/*-dao.xml",
"classpath:/spring/*-service.xml",
"classpath:/spring/consumer.xml" };
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(contextConfigurations);
/*
String[] beans = context.getBeanDefinitionNames();
for(String bean : beans) {
System.out.println(bean);
}*/
workMainService = (WorkMainService)context.getBean("workMainServiceImpl");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询