Druid是Java语言中最好的数据库连接池,提供强大的监控和扩展功能。
配置完成后,访问 项目地址/+druid/+login.html
# 本地开发 spring: datasource: username: root password: 123456 url: jdbc:mysql://localhost:3306/tqj_sys?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&allowMultiQueries=true driver-class-name: com.mysql.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource配置代码
package com.lzby.tqj.config; import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.support.http.StatViewServlet; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import javax.sql.DataSource; import java.util.HashMap; import java.util.Map; public class DruidConfig { @Bean @ConfigurationProperties(prefix = "spring.datasource") public DataSource druidDataSource() { return new DruidDataSource(); } @Bean public ServletRegistrationBean statViewServlet() { ServletRegistrationBeanstatViewServlet = new ServletRegistrationBean<>(new StatViewServlet()); // 初始化参数设置 Map initParameters = new HashMap<>(); initParameters.put("loginUsername", "admin"); initParameters.put("loginPassword", "123456"); // 白名单 initParameters.put("allow", ""); statViewServlet.setInitParameters(initParameters); return statViewServlet; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)