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

kjhwq 2017-07-17 04:00:33
这是controll代码
这是service
seviceimpl
sping-mvc
普通的访问项目就没问题,用控制层里Login/getLogin.do就报错
Servlet.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 cause
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)}
...全文
679 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
@RequestMapping("/Login")试试
小兔爷 2017-07-17
  • 打赏
  • 举报
回复
这个我遇到过,归根结底估计就是你配置没配好导致注解失败,看下是否有对service包进行注解扫描 在application.xml <!-- 启动组件扫描,排除@Controller组件,该组件由SpringMVC配置文件扫描 --> <context:component-scan base-package="xxx.xxx.xxx"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> 在spring-mvc.xml <!--自动扫描且只扫描@Controller --> <context:component-scan base-package="xxx.xxx.controller" use-default-filters="false"> </context:component-scan>
mtian2020 2017-07-17
  • 打赏
  • 举报
回复
controller请求路径注解好像有问题 @RequestMapping("/Login")试试
kjhwq 2017-07-17
  • 打赏
  • 举报
回复
引用 5 楼 yanghaimingg 的回复:
@Service("*.UserService") service实现类注入接口UserService的全路径试试
现在像在controll里面Login/getLogin.do访问不到项目页面。提示页面不能正确重定向
xwn_2016 2017-07-17
  • 打赏
  • 举报
回复
把getLogin这个名字改了就可以了
kjhwq 2017-07-17
  • 打赏
  • 举报
回复
引用 5 楼 yanghaimingg 的回复:
@Service("*.UserService") service实现类注入接口UserService的全路径试试
现在不报错了,但是访问不到页面
mtian2020 2017-07-17
  • 打赏
  • 举报
回复
@Service("*.UserService") service实现类注入接口UserService的全路径试试
kjhwq 2017-07-17
  • 打赏
  • 举报
回复
引用 1 楼 kjhwq 的回复:
appcaltionContext
引用 2 楼 yanghaimingg 的回复:
@Service service你没注入
不行,还是报错
李德胜1995 2017-07-17
  • 打赏
  • 举报
回复
UserServiceImpl加上@Service注解。。。。
mtian2020 2017-07-17
  • 打赏
  • 举报
回复
@Service service你没注入
kjhwq 2017-07-17
  • 打赏
  • 举报
回复

appcaltionContext

81,092

社区成员

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

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