I have two Maven projects called "common" & "member". I put my MySQL connection config file(application.properties
) in common project.
spring.datasource.url=jdbc:mysql://localhost:3306/train?serverTimezone=Asia/Shanghai&characterEncoding=UTF8
spring.datasource.username=train
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
And I put "common" Maven dependency in "member" project, but when I started "member" project, it can't read application.properties
in "common" project. So it appears:
37.677 WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext:592 restartedMain Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Failed to determine a suitable driver class
37.684 INFO o.a.c.core.StandardService :173 restartedMain Stopping service [Tomcat]
37.726 INFO o.s.b.a.l.ConditionEvaluationReportLogger:82 restartedMain
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
37.780 ERROR o.s.b.d.LoggingFailureAnalysisReporter:40 restartedMain
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and 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).
I'm sure something necessary have already add in "common" & "member":
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
So, how my "member" can't read the application.properties
in "common"?