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).

2019年8月7日 星期三

DBCP和c3p0連線timeout設置

因為預設值都是indefinitely無限制等待
如果Connection Pool滿載,應用程式要不到閒置的Connection,會造成應用程式的Block無任何反應
建議一定要設定 timeout

https://blog.csdn.net/qq_34359363/article/details/72763491
DBCP 
最小连接数 minIdle(預設值為0)
初始化连接数 initialSize(預設值為0)
最大连接数 maxTotal(預設值為8)
最大等待时间 maxWaitMillis(預設值為無限毫秒)
詳細資訊 https://commons.apache.org/proper/commons-dbcp/configuration.html
Hibernate要設定hibernate.dbcp.maxWaitMillis

c3p0    
最小连接数 minPoolSize(預設值為3)
初始化连接数 initialPoolSize(預設值為3)
最大连接数 maxPoolSize(預設值為15)
最大等待时间 maxIdleTime(預設值為無限秒)
詳細資訊 https://www.mchange.com/projects/c3p0/#maxIdleTime
Hibernate要設定hibernate.c3p0.maxIdleTime