Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Spring boot configuration druid

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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 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;}}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report