除了在 AWS Elastic Beanstalk 中之外,我都得到了此信息,但该应用程序可以在本地运行。
01-Aug-2018 07:44:54.815 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
Caused by: org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://d-use1-xx.xxxxxxxxxxx.us-east-1.rds.amazonaws.com:3306/xxxxxxxxxxx
正确指定了 JDBC URL。我在 file.war/WEB-INF/classes/application.properties
spring.datasource.url = jdbc:mysql://d-use1-xx.xxxxxxxxxx.us-east-1.rds.amazonaws.com:3306/xxxxxxxxx
spring.datasource.username = xxxx
spring.datasource.password = xxxxxxxxx
我的 WAR 文件中有 \WEB-INF\lib\mysql-connector-java-5.1.46.jar
。
我不知道这是否重要,但我最近为 Spring Security OAuth2 添加了 JDBC TokenStore 并将其添加到主类中。
@SpringBootApplication
@MapperScan("com.xxxxxx.xxxxxx.mapper")
public class XxxxxxxxxxxxApplication extends SpringBootServletInitializer {
@Bean(name = "OAuth")
@ConfigurationProperties(prefix="spring.datasource")
public DataSource secondaryDataSource() {
return DataSourceBuilder.create().build();
}
我不知道这是否重要(以前从未这样做过),但有一个空的环境变量集
01-Aug-2018 07:44:38.290 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -DJDBC_CONNECTION_STRING=
最佳答案
您需要添加spring.datasource.driver-class-name
配置属性:
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
JDBC 自动驱动程序加载仅适用于应用程序的初始(系统)类路径上的驱动程序,但位于 WEB-INF/lib
中的驱动程序稍后添加到上下文类路径中并且无法自动加载。
这意味着您需要显式加载它们,如果您指定spring.datasource.driver-class-name
,这就是Spring Boot所做的事情。 (或者您发现的环境变量 SPRING_DATASOURCE_DRIVER_CLASS_NAME
)。
关于java - Spring Boot + Flyway + AWS : Caused by: java. sql.SQLException:找不到合适的驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51637897/