2 wanglusimida wanglusimida 于 2017.01.11 12:12 提问

spring+mybatis中注解Controller时,启动时会报错,求大神帮忙,很急! 5C
  • org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hotelManageController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.jianpai.vegetablecalf.service.indent.IndentService] found for dependency [com.jianpai.vegetablecalf.service.indent.IndentService]: 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:321)
  • at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
  • at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
  • at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  • at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  • at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  • at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  • at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  • at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776)
  • at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
  • at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
  • at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
  • at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
  • at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
  • at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5099)
  • at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5615)
  • at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
  • at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
  • at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
  • at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
  • at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260)
  • at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2002)
  • at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
  • at java.util.concurrent.FutureTask.run(FutureTask.java:262)
  • at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  • at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  • at java.lang.Thread.run(Thread.java:745)
  • Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.jianpai.vegetablecalf.service.indent.IndentService] found for dependency [com.jianpai.vegetablecalf.service.indent.IndentService]: 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=)}

10个回答

wangb_java
wangb_java   2017.01.11 12:40

创建'hotelManageController' 的时候报错,这个Controller里面依赖的com.jianpai.vegetablecalf.service.indent.IndentService找不到

wanglusimida
wanglusimida 为什么找不到呢,我的indentService确实存在的
11 个月之前 回复
JE_GE
JE_GE   2017.01.11 13:47

注入失败,
看set方法是否正确
有无实现类
实现类是否多个

wanglusimida
wanglusimida 实现类就一个,那里的set方法,请教一下,我是小菜鸟~
11 个月之前 回复
admi_nistrator
admi_nistrator   2017.01.11 13:52

这个最好是帖一下代码。检查一下service的实现类有么有添加注解

wanglusimida
wanglusimida 有的~
11 个月之前 回复
qq_36740035
qq_36740035   2017.01.11 13:51

@Autowired 或者
@Resource(name="indentService")
private IndentService indentService;

qq_36740035
qq_36740035 回复wanglusimida: 你把service层和controller层的代码贴出来看看吧
11 个月之前 回复
wanglusimida
wanglusimida 试了,也不行~
11 个月之前 回复
bjjoy2009
bjjoy2009   2017.01.11 14:00

实现类上加注解

@Service("indentService")
public class IndentServiceImpl implements IndentService{}
实现类和接口都不能少。

还有确定那个springmvc配置里边的有个,这个路径下面是否包含你用注解的这些类。
确定有这个配置mvc:annotation-driven/

qq_36740035
qq_36740035 回复wanglusimida: 你把service层和controller层的代码贴出来看看吧
11 个月之前 回复
wanglusimida
wanglusimida 我加上了这个@Service("indentService"),他还是在报错误
11 个月之前 回复
bjjoy2009
bjjoy2009   2017.01.11 14:03

上面复制代码跪了,重发一下
还有确定那个springmvc配置里边的有下面这个配置,这个com.*路径下面是否包含你用注解的这些类

下面是注解方式注入配置,也得确认下
mvc:annotation-driven

bjjoy2009
bjjoy2009   2017.01.11 14:04

就是出不来啊,啥编辑器
context:component-scan base-package="cn.com.*"

bjjoy2009
bjjoy2009 回复路Sir: 不是吧,是扫描所有java的package是com.jianpai.vegetablecalf下面及其子目录的类。比如com.jianpai下面如果有类的话就扫描不到
11 个月之前 回复
wanglusimida
wanglusimida <!-- 自动扫描 --> <context:component-scan base-package="com.jianpai.vegetablecalf" /> ,我这个是直接扫描整个项目吗
11 个月之前 回复
engchina
engchina   Rxr 2017.01.11 15:36

com.jianpai.vegetablecalf.service.indent.IndentService
的实现类上加上@Service

如下

@Service
public class IndentServiceImpl implements IndentService
oXinLiang12
oXinLiang12   2017.01.11 18:59

肯定是你的包没有扫描到,试着把你的包范围缩小试试看~

qq_31289415
qq_31289415   2017.01.12 14:01
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!