spring 错误:org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.hibernate.SessionFactory] found for dependency:
在做sshe整合测试的时候,测到hibernate整合spring的时候出现上面的错误,错误原因就是sessionfactory没有注入进来所以报错
原因如下:ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:spring.xml","classpath:spring-hibernate.xml");
UserServiceI userService = (UserServiceI) ac.getBean("userService");
UserDao userDao = (UserDao) ac.getBean("userDao");
System.out.println("ac"+ac);
Tuser tuser = new Tuser();
tuser.setId(UUID.randomUUID().toString());
tuser.setName("ac");
tuser.setPwd("aaaaa");
userService.save(tuser);
开始的时候只写了spring.xml后面的没写,没写当然不可能注入sessionfactory了,这个错误真心不该犯啊