jt_s8645
2017-12-25 14:20
采纳率: 45.5%
浏览 1.8k
已采纳

SSM整合时出现的一个问题,网上找了资料,对比配置感觉没有问题,困扰好长时间,求大神解答疑惑?

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(mappedName=, shareable=true, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)}
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4042)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(mappedName=, shareable=true, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1100)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:441)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:419)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:544)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:155)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:304)
... 43 more

以下是配置文件
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

10条回答 默认 最新

  • huhuhuHR 2017-12-25 15:21
    已采纳

    这几天才搭的一个springmvc。
    给你参考一下:https://github.com/huhuhuHR/springmvc
    有几点注意:
    1。controller类要加@Controller,
    2。service类要加@Service,
    3。dao层如果和mybaits整合mapper namespace="x x x x">命名空间要对应
    4。<!-- 4.扫描web相关的bean -->要包含你所有写的@Controller,@Service
    5。xml整合mybatis
    <!-- 3.配置SqlSessionFactory对象 -->

    <!-- 注入数据库连接池 -->

    <!-- 配置MyBaties全局配置文件:mybatis-config.xml -->

    <!-- 扫描entity包 使用别名 -->

    <!-- 扫描sql配置文件:mapper需要的xml文件 -->

    <!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 注入sqlSessionFactory -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
        <!-- 给出需要扫描Dao接口包 -->
        <property name="basePackage" value="com.huhuhu.dao"/>
    </bean>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 裴某某 2017-12-25 14:44

    userController这个Bean没有,检查一下

    评论
    解决 无用
    打赏 举报
  • Q544471255 2017-12-25 14:59

    No qualifying bean of type [service.UserService] found for dependency:

    这个检查下,看看UserService是不是没添加@Service这个注解.

    评论
    解决 无用
    打赏 举报
  • qujingluoping 2017-12-25 15:17

    应该是UserService没添加@Service这个注解.

    评论
    解决 无用
    打赏 举报
  • catfishlyf 2017-12-25 15:23

    您好,如果是用xml配置的,确定下bean的name(id)是否正确,配置是否完整;
    如果是用注解,确定下你xml配置里面的扫描包是否扫描到了UserService这个java类所在的包,(检查UserService是否拼写正确)并且看下UserService类的注解配置是否正确(是否缺少@Service注解)
    检查配置文件一定要非常细心,不能放过每一个名字

    如果我的回答帮助到了您,请采纳,谢谢支持!

    评论
    解决 无用
    打赏 举报
  • biglongking 2017-12-26 00:01

    如果使用注解 需要配置地洞扫描

    评论
    解决 无用
    打赏 举报
  • 杨_5426 2017-12-26 01:45

    为啥配置文件看不了

    评论
    解决 无用
    打赏 举报
  • 十三月流萤 2017-12-26 03:00

    一定要注意配置文件里面的标签的顺序,部分标签顺序不对,会出现你意想不到的错误。具体你可以看看官方文档对顺序的一些要求

    评论
    解决 无用
    打赏 举报
  • 路漫漫兮其修远兮 2017-12-26 06:18

    包扫描要扫描到service所在的包,然后类头上添加@service注解,注意@service的包名,避免用了别的jar包的@service

    评论
    解决 无用
    打赏 举报
  • 席儒 2017-12-26 09:32

    遇到此类诸如找不到bean的问题,教你一个通用的方法,单元测试从配置文件中逐层取bean,建议你从dao层的bean开始取,一层一层往上排查,总能查出对应的bug

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题