@Configuration
public class AppConfig {
@Bean
public SessionFactory sessionFactory() throws Exception{
AnnotationSessionFactoryBean factory =new AnnotationSessionFactoryBean();
factory.setDataSource(dataSource());//设置数据据
factory.setPackagesToScan(new String[]{"algz.platform"});
factory.afterPropertiesSet();
return factory.getObject();
}DAO:@Repository("SQLiteDao")
public class SQLiteDaoImpl implements SQLiteDao {
@Autowired
private SessionFactory sessionFactory;
启动报错:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=sessionFactory)}
请问怎样在DAO层注入进来。
javaconfigspring3annotationsautowired
解决方案 »
- 项目中加了url地址重写功能,可是总是不成功
- java s:if标签中可不可以放入input
- jsp 一直运行错误!救命!
- 讨论一个校园项目的开发问题
- 关于定时器在WEB启动时应用的问题
- 谁有JSP+Mysql 简单的数据浏览、添加、修改和删除代码?
- 哪位有javabean实现的,jsp显示记录集表格封装到javabean中的
- 为什么写进数据库里的汉字是乱码,我已经用:response.setCharacterEncoding("gb2312");转码了啊?
- 提个简单的问题
- JSP中表单怎么设置才能把table放在网页的中间显示
- springMVC使用aop的问题,实现用户操作监控
- 新人求教,怎么在JSTL中叠加给一个变量赋值?
思路是这样,具体语法找百度
DAO类上应为@Repository;service类上@service。这与我的问题不相关。我的其他注入都正常,就是sessionFactory注入进来。因为是javaConfig写法。