springboot2.0 常见问题找不到dao
2019-05-17 12:04
232 查看
报错信息如下
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.1.RELEASE) 2019-05-17 11:59:15.026 INFO 7792 --- [ main] com.bdqn.Start : Starting Start on PC-20180826RQMV with PID 7792 (E:\IDEA\springboot1\target\classes started by Administrator in E:\IDEA\springboot1) 2019-05-17 11:59:15.031 INFO 7792 --- [ main] com.bdqn.Start : The following profiles are active: dev 2019-05-17 11:59:15.115 INFO 7792 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4f6ee6e4: startup date [Fri May 17 11:59:15 CST 2019]; root of context hierarchy 2019-05-17 11:59:16.638 INFO 7792 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8888 (http) 2019-05-17 11:59:16.663 INFO 7792 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2019-05-17 11:59:16.663 INFO 7792 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.29 2019-05-17 11:59:16.667 INFO 7792 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : Loaded APR based Apache Tomcat Native library [1.2.18] using APR version [1.6.5]. 2019-05-17 11:59:16.668 INFO 7792 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. 2019-05-17 11:59:16.668 INFO 7792 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true] 2019-05-17 11:59:16.671 INFO 7792 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.1 11 Sep 2018] 2019-05-17 11:59:16.864 INFO 7792 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 2019-05-17 11:59:16.867 INFO 7792 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2019-05-17 11:59:16.868 INFO 7792 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1759 ms 2019-05-17 11:59:16.998 INFO 7792 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/] 2019-05-17 11:59:17.002 INFO 7792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2019-05-17 11:59:17.002 INFO 7792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2019-05-17 11:59:17.002 INFO 7792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2019-05-17 11:59:17.002 INFO 7792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2019-05-17 11:59:17.041 WARN 7792 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testController': Unsatisfied dependency expressed through field 'testService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testServices': Unsatisfied dependency expressed through field 'testDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.bdqn.dao.TestDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 2019-05-17 11:59:17.044 INFO 7792 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2019-05-17 11:59:17.052 WARN 7792 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: java.lang.Object.wait(Native Method) java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144) com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43) 2019-05-17 11:59:17.061 INFO 7792 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-05-17 11:59:17.194 ERROR 7792 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Field testDao in com.bdqn.service.TestServices required a bean of type 'com.bdqn.dao.TestDao' that could not be found. Action: Consider defining a bean of type 'com.bdqn.dao.TestDao' in your configuration. Process finished with exit code 1
这种报错情况有两种:
第一种:启动类注解上有@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
解决办法 去掉(exclude = DataSourceAutoConfiguration.class)
第二种:dao的接口使用注解 @Repository
解决办法:将 @Repository修改为@Mapper
情况一:
启动类:
package com.bdqn; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) public class Start { public static void main(String[] args) { SpringApplication.run(Start.class,args); } }
Dao层
package com.bdqn.dao; import com.bdqn.pojo.Test; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; import java.util.List; @Mapper public interface TestDao { @Select("select * from user") List<Test> getAll(); }
解决办法:将启动类后面的(exclude = DataSourceAutoConfiguration.class)去掉
package com.bdqn; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; @SpringBootApplication public class Start { public static void main(String[] args) { SpringApplication.run(Start.class,args); } }
情况二:
启动类
@SpringBootApplication public class Start { public static void main(String[] args) { SpringApplication.run(Start.class,args); }
dao层
package com.bdqn.dao; import com.bdqn.pojo.Test; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; import java.util.List; @Repository public interface TestDao { @Select("select * from user") List<Test> getAll(); }
解决办法:将@Repository修改为@Mapper
(adsbygoogle = window.adsbygoogle || []).push({});相关文章推荐
- SpringBoot 2.0中SpringWebContext 找不到无法使用的问题解决
- springboot 常见问题
- spring-boot常见问题总结
- SpringBoot 2.0返回Date问题。
- springboot之Filter指定过滤URL的常见问题
- Spring Boot常见问题笔记
- SpringBoot项目打包后,找不到文件路径问题,处理方法
- Spring Boot2.0中SpringWebContext找不到无法使用的解决方法
- 解决spring boot上传文件MultipartFile找不到,报错的问题
- springBoot常见问题
- easyui+springboot +poi实现导出(excel2007)与导入(常见问题的总结)
- springboot邮件发送功能和两个常见问题
- 有关于springBoot2.0找不到js文件的说明
- spring boot 2.0 跨域问题
- SpringBoot常见问题
- SpringBoot项目打包后,找不到文件路径问题,处理方法
- SpringBoot常见问题(一)--启动报错(Cannot determine embedded database driver class for database type NONE)
- 解决springboot项目打war 包docker包找不到resource 下的静态资源问题
- Spring Boot常见问题的解决方式
- springboot 2.0 集成 shiro 和 thymeleaf-extras-shiro 2.0 使用过程遇到的问题