报错信息如下
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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);
}
}
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();
}
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);
}
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();
}