Cannot resolve reference to bean 'ItemCatService' while setting bean property 'ref'

严重: Exceptionsending context initialized event to listener instance of classorg.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'cn.e3mall.service.ItemCatService': Cannotresolve reference to bean 'ItemCatService' while setting bean property 'ref';nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:No bean named 'ItemCatService' is defined


出现这个问题的原因有两个

 

一:注解问题

 

在实现类中没有加相应的注解。如dao层 @Repository  service @Service

 

web @Controller

 

二:配置文件有问题

 

 

如果注解没错,那就是配置文件有错,要么少写了点什么,要么多写了点什么,好好检查配置的路径,大小写字母

 

分享一下我犯的错:

 

在我反反复复的检查了注解之后,只能来查配置文件

 

1.dubbo发布服务的时候,applicationContext-service.xml配置文件中itemCatServiceImpl这个单词写错了





2.后来发现itemCatServiceImpl类的名字写成了itemCatServiceImp



Cannot resolve reference to bean 'ItemCatService' while setting bean property 'ref'_第1张图片


为什么写错这两个地方就会出错呢?

 

服务端的配置文件applicationContext-service.xml 用这段代码自动扫描




 xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的java文件,如果扫描到有@Component @Controller@Service等这些注解的类,则把这些类注册为bean

 

dubbo和spring一块使用,ref引用已存在的service服务(即已存在的spring bean对象),service才把已有的service服务发布成dubbo服务

 

此段代码声明需要暴露的服务接口,将服务发布到注册中心,消费者就可以用了





ref="ItemServiceImpl",这里的ItemServiceImpl就是去找类ItemServiceImpl,这是一个约定,将 ref="XXX"中,将类XXX第一个字母小写。

 

如果在此处不用自动扫描方法:

 

则需要自己配置bean






这样配置的话只需要将beanid的值和ref中的值相等就可以了

 

像我这样,ref中的值和类名不对应,当然会报找不到bean的错误


你可能感兴趣的:(✈项目)