spring.datasource.schema配置詳解
用springboot2.0執(zhí)行sql腳本:
1.現(xiàn)將sql文件放在resources下的sql文件夾下

2.新建數(shù)據(jù)庫(kù)mybatis
3.配置yml
spring:
datasource:
# 數(shù)據(jù)源基本配置
username: root
password: 123
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
type: com.alibaba.druid.pool.DruidDataSource
# 數(shù)據(jù)源其他配置
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
# 配置監(jiān)控統(tǒng)計(jì)攔截的filters,去掉后監(jiān)控界面sql無(wú)法統(tǒng)計(jì),'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
注意:

配置類(lèi):
package com.example.springbooy06datamybatis.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class DruidConfig {
@ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource druid(){
return new DruidDataSource();
}
//配置Druid的監(jiān)控
//1、配置一個(gè)管理后臺(tái)的Servlet
@Bean
public ServletRegistrationBean statViewServlet(){
ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
Map<String,String> initParams = new HashMap<>();
initParams.put("loginUsername","admin");
initParams.put("loginPassword","123456");
initParams.put("allow","");//默認(rèn)就是允許所有訪(fǎng)問(wèn)
initParams.put("deny","192.168.15.21");
bean.setInitParameters(initParams);
return bean;
}
//2、配置一個(gè)web監(jiān)控的filter
@Bean
public FilterRegistrationBean webStatFilter(){
FilterRegistrationBean bean = new FilterRegistrationBean();
bean.setFilter(new WebStatFilter());
Map<String,String> initParams = new HashMap<>();
initParams.put("exclusions","*.js,*.css,/druid/*");
bean.setInitParameters(initParams);
bean.setUrlPatterns(Arrays.asList("/*"));
return bean;
}
}
執(zhí)行成功?。?/p>

到此這篇關(guān)于spring.datasource.schema配置詳解的文章就介紹到這了,更多相關(guān)spring.datasource.schema配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java線(xiàn)程中synchronized的用法與原理解析
這篇文章主要介紹了Java線(xiàn)程中synchronized的用法與原理解析,只要有線(xiàn)程,就會(huì)有并發(fā)的現(xiàn)象,也同時(shí)會(huì)產(chǎn)生數(shù)據(jù)不一致,那么對(duì)于需要使用同一個(gè)數(shù)據(jù)的兩個(gè)線(xiàn)程,就會(huì)產(chǎn)生沖突,那么就引出了鎖的概念,本篇會(huì)針對(duì)性的說(shuō)下synchronized這個(gè)關(guān)鍵字,需要的朋友可以參考下2024-01-01
Java Stream中自定義Collector實(shí)現(xiàn)復(fù)雜數(shù)據(jù)收集的方法
Java Stream API中的Collector接口是一個(gè)強(qiáng)大的工具,它允許我們自定義數(shù)據(jù)收集、轉(zhuǎn)換和聚合的過(guò)程,,本文介紹了Java Stream中自定義Collector實(shí)現(xiàn)復(fù)雜數(shù)據(jù)收集方法,需要的朋友可以參考下2024-08-08
idea2023遠(yuǎn)程調(diào)試springboot的過(guò)程詳解
這篇文章主要介紹了idea2023遠(yuǎn)程調(diào)試,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-08-08
Java生成10個(gè)1000以?xún)?nèi)的隨機(jī)數(shù)并用消息框顯示數(shù)組內(nèi)容然后求和輸出
這篇文章主要介紹了Java生成10個(gè)1000以?xún)?nèi)的隨機(jī)數(shù)并用消息框顯示數(shù)組內(nèi)容然后求和輸出,需要的朋友可以參考下2015-10-10
java接口用戶(hù)上下文的設(shè)計(jì)與實(shí)現(xiàn)
這篇文章主要為大家介紹了接口用戶(hù)上下文的設(shè)計(jì)與實(shí)現(xiàn)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11

