spring boot 配置druid
发表于:2025-01-24 作者:千家信息网编辑
千家信息网最后更新 2025年01月24日,application.yamlspring: main: banner-mode: console datasource: type: com.alibaba.druid.pool.
千家信息网最后更新 2025年01月24日spring boot 配置druid
application.yaml
spring: main: banner-mode: console datasource: type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://localhost:3306/test username: test password: 123456# driver-class-name: com.mysql.jdbc.Driver# druid pool customize configuration driverClassName: com.mysql.jdbc.Driver initialSize: 10 minIdle: 5 maxActive: 20 maxWait: 60000 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 1 from dual testWhileIdle: true testOnBorrow: false testOnReturn: false removeAbandoned: true removeAbandonedTimeout: 1800 logAbandoned: true filters: stat,wall,slf4j logSlowSql: true loginUsername: test loginPassword: 123456 jdbc: template: max-rows: 1000 query-timeout: 1200 jpa: hibernate: naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpllogging: level: root: debug
DruidConfiguration
@Component@ConfigurationProperties(prefix = "spring.datasource")public class DruidConfiguration { private String url; private String username; private String password; private String driverClassName; private int initialSize; private int minIdle; private int maxActive; private int maxWait; private int timeBetweenEvictionRunsMillis; private int minEvictableIdleTimeMillis; private String validationQuery; private boolean testWhileIdle; private boolean testOnBorrow; private boolean testOnReturn; private boolean removeAbandoned; private int removeAbandonedTimeout; private boolean logAbandoned; private String filters; private boolean logSlowSql; private String loginUsername; private String loginPassword;}
@Configuration配置
@Configurationpublic class CustomizeConfig { private final static Logger LOGGER = LoggerFactory.getLogger(CustomizeConfig.class); @Autowired private DruidConfiguration druidConfiguration; @Bean public DataSource druidDataSource(){ DruidDataSource datasource = new DruidDataSource(); datasource.setUrl(druidConfiguration.getUrl()); datasource.setUsername(druidConfiguration.getUsername()); datasource.setPassword(druidConfiguration.getPassword()); datasource.setDriverClassName(druidConfiguration.getDriverClassName()); datasource.setInitialSize(druidConfiguration.getInitialSize()); datasource.setMinIdle(druidConfiguration.getMinIdle()); datasource.setMaxActive(druidConfiguration.getMaxActive()); datasource.setMaxWait(druidConfiguration.getMaxWait()); datasource.setTimeBetweenEvictionRunsMillis(druidConfiguration.getTimeBetweenEvictionRunsMillis()); datasource.setMinEvictableIdleTimeMillis(druidConfiguration.getMinEvictableIdleTimeMillis()); datasource.setValidationQuery(druidConfiguration.getValidationQuery()); datasource.setTestWhileIdle(druidConfiguration.isTestWhileIdle()); datasource.setTestOnBorrow(druidConfiguration.isTestOnBorrow()); datasource.setTestOnReturn(druidConfiguration.isTestOnReturn()); datasource.setRemoveAbandoned(druidConfiguration.isRemoveAbandoned()); datasource.setRemoveAbandonedTimeout(druidConfiguration.getRemoveAbandonedTimeout()); datasource.setLogAbandoned(druidConfiguration.isLogAbandoned()); try { datasource.setFilters(druidConfiguration.getFilters()); } catch (SQLException e) { LOGGER.error("datasource.setFilters occur error.", e); } return datasource; } @Bean public ServletRegistrationBean druidServlet() { ServletRegistrationBean reg = new ServletRegistrationBean(); reg.setServlet(new StatViewServlet()); reg.addUrlMappings("/druid/*"); reg.addInitParameter("loginUsername", druidConfiguration.getLoginUsername()); reg.addInitParameter("loginPassword", druidConfiguration.getLoginPassword()); reg.addInitParameter("logSlowSql", String.valueOf(druidConfiguration.isLogSlowSql())); return reg; } @Bean public FilterRegistrationBean filterRegistrationBean() { FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); filterRegistrationBean.setFilter(new WebStatFilter()); filterRegistrationBean.addUrlPatterns("/*"); filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); filterRegistrationBean.addInitParameter("profileEnable", "true"); return filterRegistrationBean; }}
配置
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
山东本土数据库
惠普服务器网卡pcie引脚图
简述两种数据库技术的区别
一开始我以为是服务器负载太大了
客悠网络技术
人民对网络安全职责
泰坦之旅手游服务器在哪里
网络安全宣传周上海主场
网络安全作业人员配备标准
网络安全的第三方是指什么
南宁市公安网络安全中心
软件开发者报告
上下位机软件开发
四级以上网络安全事件
svn服务器搭建和管理
绿书签网络安全课
安装数据库exception
泛欧网络安全中心什么时候成立
高中网络安全制度建立及落实情况
如何搜索软件开发作者
公司邮箱的服务器名称
泰坦之旅手游服务器在哪里
德州智慧团建软件开发公司
网络安全产业链前景
sql数据库期末考试
群控软件开发多钱
舟山网络安全工程师招聘
四川科技软件开发公司排名
网络安全黑板报一
服务器密码忘记怎么关机