开发者社区> 问答> 正文

启动时报错BeanCreationException-java报错

启动时报错BeanCreationException:

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'userController':
Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.caizhaotu.dao.user.UserRepository com.caizhaotu.controller.user.UserController.userRepository;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.util.NoSuchElementException

展开
收起
montos 2020-05-28 13:19:17 694 0
1 条回答
写回答
取消 提交回答
  • 解决:application.java 可以放在controller、service、dao层都可以,但是要保证application.java 包位置处于所有层的上级,比如com.xxx.web、com.xxx.service、com.xxx.dao。把application.java放在com.xxx即可。@SpringBootApplication 注解效果等于 @Configuration,@EnableAutoConfiguration 及 @ComponentScan 这三个注解一起使用,所以不要在 Controller 在启动类上面添加 @EnableAutoConfiguration 。

    2020-05-28 16:23:04
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载