我的项目启动时报错:
Description:
Field bannerRepository in com.zhou.wade.service.impl.BannerServiceImpl required a bean of type 'com.zhou.wade.repository.BannerRepository' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.zhou.wade.repository.BannerRepository' in your configuration.
网上大多数说是扫描不到包,需要手动添加扫描
(1) @ComponentScan(basePackages = "xxx.xxx.xxx"):扫描 @Controller、@Service 注解; (2) @EnableJpaRepositories(basePackages = "xxx.xxx.xxx"):扫描 @Repository 注解; (3) @EntityScan(basePackages = "xxx.xxx.xxx"):扫描 @Entity 注解;
尝试了一下,发现都不行。
- 最后将exclude = {DataSourceAutoConfiguration.class}删除
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class WadeApplication {
public static void main(String[] args) {
SpringApplication.run(WadeApplication.class, args);
}
}
但是此时又报另一个错,原来自己犯了低级错误。。。
2020-03-19 11:53:54.286 INFO 7852 --- [ restartedMain] com.zhou.wade.WadeApplication : Starting WadeApplication on USER-20170308ID with PID 7852 (E:\GZ\a\wade\target\classes started by Administrator in E:\GZ\a\wade)
2020-03-19 11:53:54.290 INFO 7852 --- [ restartedMain] com.zhou.wade.WadeApplication : The following profiles are active: dev
2020-03-19 11:53:54.347 INFO 7852 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in E:\IDEAPROJECT\apache-maven-3.6.0\rep\org\glassfish\jaxb\jaxb-runtime\2.3.2\jaxb-runtime-2.3.2.jar referenced one or more files that do not exist: file:/E:/IDEAPROJECT/apache-maven-3.6.0/rep/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.xml.bind-api-2.3.2.jar,file:/E:/IDEAPROJECT/apache-maven-3.6.0/rep/org/glassfish/jaxb/jaxb-runtime/2.3.2/txw2-2.3.2.jar,file:/E:/IDEAPROJECT/apache-maven-3.6.0/rep/org/glassfish/jaxb/jaxb-runtime/2.3.2/istack-commons-runtime-3.0.8.jar,file:/E:/IDEAPROJECT/apache-maven-3.6.0/rep/org/glassfish/jaxb/jaxb-runtime/2.3.2/stax-ex-1.8.1.jar,file:/E:/IDEAPROJECT/apache-maven-3.6.0/rep/org/glassfish/jaxb/jaxb-runtime/2.3.2/FastInfoset-1.2.16.jar,file:/E:/IDEAPROJECT/apache-maven-3.6.0/rep/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.activation-api-1.2.1.jar
2020-03-19 11:53:54.347 INFO 7852 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-03-19 11:53:54.347 INFO 7852 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-03-19 11:53:55.147 INFO 7852 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-19 11:53:55.238 INFO 7852 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 79ms. Found 2 JPA repository interfaces.
2020-03-19 11:53:55.601 INFO 7852 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-19 11:53:55.929 INFO 7852 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8001 (http)
2020-03-19 11:53:55.940 INFO 7852 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-19 11:53:55.940 INFO 7852 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.29]
2020-03-19 11:53:56.062 INFO 7852 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-19 11:53:56.062 INFO 7852 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1715 ms
2020-03-19 11:53:56.127 WARN 7852 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-03-19 11:53:56.130 INFO 7852 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-03-19 11:53:56.139 WARN 7852 --- [ restartedMain] 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:142)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
2020-03-19 11:53:56.151 INFO 7852 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-19 11:53:56.161 ERROR 7852 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
url填错了。。。
少了jdbc:mysql指定
spring:
datasource:
url: jdbc://localhost:3306/b_wade?characterEncoding=utf-8&serverTimezone=GMT%2B8
username: root
password: root
- 正确:
spring:
datasource:
url: jdbc:mysql://localhost:3306/b_wade?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
username: root
password: root
- 最后还需要指定驱动名
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/b_wade?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
username: root
password: root