IDEA使用 @Autowired和@Resource时报错

使用IDEA工具时使用@Resource和@Autowired自动注解bean时会显示红色。
解决方法: 

File – Settings – Inspections。在Spring Core – Autowring for Bean Class 中将Severity的级别由之前的error改成warning。

如图:



maven项目Spring MVC中使用@Autowired报错

07-17

这是controll代码[img=http://img.bbs.csdn.net/upload/201707/17/1500278029_496016.png][/img]rn这是service[img=http://img.bbs.csdn.net/upload/201707/17/1500278101_382487.png][/img]rnseviceimpl[img=http://img.bbs.csdn.net/upload/201707/17/1500278144_29374.png][/img]rnsping-mvc[img=http://img.bbs.csdn.net/upload/201707/17/1500278239_752525.png][/img]rn普通的访问项目就没问题,用控制层里Login/getLogin.do就报错rnServlet.service() for servlet [SpringMVC] in context with path [/center] threw exception [Request processing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private goss.service.UserService goss.controller.LoginController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [goss.service.UserService] 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)] with root causernorg.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [goss.service.UserService] 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)

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试