javaconfig配置的sessionFactory在DAO层怎么注入进来

a_lgz 2013-03-09 08:55:47

@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层注入进来。
...全文
109 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
a_lgz 2013-03-09
  • 打赏
  • 举报
回复
引用 1 楼 wangjinqing3768 的回复:
注解注入的话 。 给你的Dao 类头前面加 @service =XXDAO , 在你要注入的地方添加 @@Repository("XXDAO") 思路是这样,具体语法找百度
DAO类上应为@Repository;service类上@service。这与我的问题不相关。我的其他注入都正常,就是sessionFactory注入进来。因为是javaConfig写法。
wangjinlong3768038 2013-03-09
  • 打赏
  • 举报
回复
注解注入的话 。 给你的Dao 类头前面加 @service =XXDAO , 在你要注入的地方添加 @@Repository("XXDAO") 思路是这样,具体语法找百度

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧