注入Dao至serviceImp的问题

江西DJ烟仔ReMix 2016-08-29 08:11:11
论坛上的各位大神们好,最近本人因dao注入到serviceImp类出现了问题,绞尽脑汁 花了大量的时间也没解决,只知到问题原因是serviceipm那里注入dao出现了错误,希望看到此贴的朋友能指点一下,本人感激不尽 代码如下:




就是这里serviceImp类userBasicInfoDao.insertUser(userBasicInfo)出现了问题,导致创建ben失败,但就是不知错在哪

















启动报错的完整代码如下:

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userBasicInfoAction': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private music.struts2.service.UserBasicInfoService music.struts2.action.UserBasicInfoAction.userBasicInfoService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userBasicInfoServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private music.struts2.dao.UserBasicInfoDao music.struts2.service.impl.UserBasicInfoServiceImpl.userBasicInfoDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [music.struts2.dao.UserBasicInfoDao] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
...全文
786 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
vita bella 2019-01-17
  • 打赏
  • 举报
回复
请问,如果我不实现Mapper的实现类,直接把它封装在Service的实现类里,怎么解决报错的问题。我在Service的实现类上写了@Controller("impl")。。。然后它走到有@Autowired注解的封装Dao层类上就报错了。这个怎么解决,如果不实现Dao层的实现类的话。。。。我看人家的项目里就是没有用到Dao层的实现类。直接封装到Service实现类的。是要配置什么吗
hlfan2 2016-09-02
  • 打赏
  • 举报
回复
少一个配置,整个都要崩
码上大侠 2016-09-02
  • 打赏
  • 举报
回复
引用 15 楼 u014598014 的回复:
[quote=引用 12 楼 Tomorrow_Morning 的回复:] 配置文件缺少MapperScannerConfigurer <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="music.struts2.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean>
大神你太厉害了,就是你说的那样,缺少那个MapperScannerConfigurer配置,怎么把分给你啊,这论坛做的不人性化,不好操作[/quote] 结贴散分
朝 花 拾 夕 2016-09-01
  • 打赏
  • 举报
回复
哎 ,没意思,这种问题,百度了 就有解决办法的啊
  • 打赏
  • 举报
回复
引用 12 楼 Tomorrow_Morning 的回复:
配置文件缺少MapperScannerConfigurer <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="music.struts2.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean>
大神你太厉害了,就是你说的那样,缺少那个MapperScannerConfigurer配置,怎么把分给你啊,这论坛做的不人性化,不好操作
snn2011 2016-08-30
  • 打赏
  • 举报
回复
把@autowired改成@Resource 这个错误说的是没有找到合适的bean类型。。
码上大侠 2016-08-30
  • 打赏
  • 举报
回复
配置文件缺少MapperScannerConfigurer <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="music.struts2.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean>
  • 打赏
  • 举报
回复
[quote=引用 楼主 u014598014 的回复:] UserBasicInfoDao 这个是mybatis的映射文件接口,不是mybatis内部自动实现的吗
  • 打赏
  • 举报
回复
引用 楼主 u014598014 的回复:
论坛上的各位大神们好,最近本人因dao注入到serviceImp类出现了问题,绞尽脑汁 花了大量的时间也没解决,只知到问题原因是serviceipm那里注入dao出现了错误,希望看到此贴的朋友能指点一下,本人感激不尽 代码如下: 就是这里serviceImp类userBasicInfoDao.insertUser(userBasicInfo)出现了问题,导致创建ben失败,但就是不知错在哪 启动报错的完整代码如下: 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userBasicInfoAction': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private music.struts2.service.UserBasicInfoService music.struts2.action.UserBasicInfoAction.userBasicInfoService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userBasicInfoServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private music.struts2.dao.UserBasicInfoDao music.struts2.service.impl.UserBasicInfoServiceImpl.userBasicInfoDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [music.struts2.dao.UserBasicInfoDao] 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)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
我加过@Repository这个注解但也是没用
  • 打赏
  • 举报
回复
怎么回复啊!!!!
今天晴 2016-08-30
  • 打赏
  • 举报
回复
在UserBasicInfoDao的实现类上注解
a4boy 2016-08-30
  • 打赏
  • 举报
回复
或者 action中 @resource 改为@autowired
  • 打赏
  • 举报
回复
坐等接分
JC_WorkSpace 2016-08-30
  • 打赏
  • 举报
回复
应该是MyBatis没有扫描并注入这个DAO,看你的配置文件并没有指明需要扫描的包路径,你可以按照12楼那位大哥的方式试试看。
codingjav 2016-08-29
  • 打赏
  • 举报
回复
上面说的很详细撒
小白晒太阳 2016-08-29
  • 打赏
  • 举报
回复
引用 3 楼 Tro_picana 的回复:
@Component(value = "userBasicInfoDao") 你那个UserBasicInfoDao上面加上这个注解 然后Service里面用@Resource
你的UserBasicInfoDao有对应的实现类吗?注解换到实现类上试试。
小白晒太阳 2016-08-29
  • 打赏
  • 举报
回复
@Component(value = "userBasicInfoDao") 你那个UserBasicInfoDao上面加上这个注解 然后Service里面用@Resource
I,Frankenstein 2016-08-29
  • 打赏
  • 举报
回复
你是不是没有给UserBasicInfoDao实现类加上注解? 另外,给楼主个建议, 1:@Service("userService");@Controller("xxAction");注解的时候加个名字稍微会好点,给后来人个看懂的机会,本来注解就挺晦涩难找的了。 2:@Autowried(required=false) 会好一点!它默认是true
方丈的寺院 2016-08-29
  • 打赏
  • 举报
回复
UserBasicInfoDao 的实现类要加上Annotation . @Component or @Repository

81,094

社区成员

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

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