解決方式:
加入以下紅字部分停用Spring Boot的資料庫自動配置
@SpringBootApplication
(exclude = DataSourceAutoConfiguration.class)
public class XXXApplication {
public static void main(String[] args) {
SpringApplication.run(
XXXApplication.class, args);
}
}
錯誤訊息
:
:: Spring Boot :: (v2.1.7.RELEASE)
2019-08-18 19:59:10.049 INFO 18260 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-18 19:59:10.049 INFO 18260 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1388 ms
2019-08-18 19:59:10.109 WARN 18260 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor 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
2019-08-18 19:59:10.111 INFO 18260 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-08-18 19:59:10.122 INFO 18260 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-08-18 19:59:10.128 ERROR 18260 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
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).