文章目錄
一、Failed to bind properties under ‘spring.datasource’ to javax.sql.DataSource
看的是尚硅谷的視頻,springboot整合druid數據源時產生的問題:
參考:https://blog.csdn.net/xingkongtianma01/article/details/81624313
導入log4j的依賴或者刪除配置文件中的log4j即可。
二、連接數據庫出現The server time zone value ‘�й���ʱ��’ is unrecogni等問題的解決方案
這個問題和mysql驅動版本太高有關,按照如下修改連接配置即可:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/springboot?serverTimezone=UTC
三、SpringBoot2.x版本自動建表
參考:https://blog.csdn.net/weixin_41334434/article/details/90380540
- 指定腳本路徑:
classpath:sql/department.sql
initialization-mode: always
spring:
datasource:
# 數據源基本配置
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/springboot?serverTimezone=UTC
type: com.alibaba.druid.pool.DruidDataSource
# 數據源其他配置
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
# 配置監控統計攔截的filters,去掉後監控界面sql無法統計,'wall'用於防火牆
filters: stat,wall,log4j
maxPoolPreparedStatementPerConnectionSize: 20
useGlobalDataSourceStat: true
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
schema:
- classpath:sql/department.sql
- classpath:sql/employee.sql
initialization-mode: always
四、Springboot與Mybatis整合相關配置問題(以駝峯命名爲例)
參考:https://www.jianshu.com/p/1507a47f43ac
【配置properties或yml】
#application.yml
mybatis:
configuration:
map-underscore-to-camel-case: true
【配置Customizer】
@org.springframework.context.annotation.Configuration
public class MyBatisConfig {
@Bean
public ConfigurationCustomizer configurationCustomizer(){
return new ConfigurationCustomizer() {
@Override
public void customize(Configuration configuration) {
configuration.setMapUnderscoreToCamelCase(true);
}
};
}
}