ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml"); HibernateDao dao = (HibernateDao) app.getBean("hibernateDao");如果是多个spring.xmlApplicationContext app = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","applicationContext2.xml"});
ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
HibernateDao dao = (HibernateDao) app.getBean("hibernateDao");如果是多个spring.xmlApplicationContext app = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","applicationContext2.xml"});
protected String[] getConfigLocations() {
setAutowireMode(AUTOWIRE_BY_NAME);
return new String[] {
"classpath*:/applicationContext-resources.xml",
"classpath*:/applicationContext-vas-group-dao.xml",
};
} 把你的web.xml 加载进去试试 不过一般测DAO就行了 怎么会用到web.xml
只需要继承:AbstractTransactionalDataSourceSpringContextTests
重写:
protected String[] getConfigLocations() {
return new String[] { "classpath*:application-persistence.xml" };
}
就可以了。。至于要spring获取web.xml还是头一次听说
即使你这样读取到web.xml,但是你的环境还是没有楼主是想把web.xml中的环境也初始化。。