2019年8月12日 星期一

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

application.properties要設定資料庫DataSource,範例如下:
spring.datasource.url=jdbc:sqlserver://localhost:1433;DatabaseName=AdventureWorks2017
spring.datasource.username=資料庫登入帳號
spring.datasource.password=資料庫登入密碼
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.properties.hibernate.default_schema=dbo



2019-08-12 22:14:57.490  INFO 21212 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-08-12 22:14:57.510  INFO 21212 --- [           main] o.apache.catalina.core.
StandardService   : Starting service [Tomcat]
2019-08-12 22:14:57.510  INFO 21212 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.22]
2019-08-12 22:14:57.628  INFO 21212 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-08-12 22:14:57.629  INFO 21212 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1034 ms
2019-08-12 22:14:57.694  WARN 21212 --- [           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-12 22:14:57.696  INFO 21212 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-08-12 22:14:57.708  INFO 21212 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-08-12 22:14:57.713 ERROR 21212 --- [           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).

沒有留言:

張貼留言