
spring boot jpa启动错误Consider defining a bean of type ‘com.example.security.dao.UserDao‘
spring boot 启动类不在根目录整合spring boot jpa启动报错:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2020-12-02 17:14:08.940 ERROR 3868 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Parameter 0 of constructor in com.example.security.service.UserServiceImpl required a bean of type 'com.example.security.dao.UserDao' that could not be found. Action: Consider defining a bean of type 'com.example.security.dao.UserDao' in your configuration. Disconnected from the target VM, address: '127.0.0.1:52540', transport: 'socket' Process finished with exit code 1解决方法: 1、需要在启动类加上以下注解 @EnableJpaRepositories(basePackages = {“com.example.security”}) @EntityScan(basePackages = {“com.example.security”})
/** * {@link EnableJpaRepositories} 扫描 @Repository 注解 * {@link EntityScan} 扫描 @Entity 注解 * {@link ComponentScan}扫描 @Controller、@Service 注解 * @author */ @SpringBootApplication @EnableJpaRepositories(basePackages = {"com.example.security"}) @EntityScan(basePackages = {"com.example.security"}) @ComponentScan({"com.example.security"}) public class BootStartApplication { public static void main(String[] args) { SpringApplication.run(BootStartApplication .class, args); } }2、将启动类移至项目根目录
参考博客:blog.csdn/guokexiaohao/article/details/79741023
👁️ 阅读量:0
© 版权声明:本文《spring boot jpa启动错误Consider defining a bean of type ‘com.example.security.dao.UserDao‘》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686554708a290582.html。