Springboot使用Druid后台监控
1.pom加入依赖
<!-- Druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.21</version>
</dependency>
2.yml中配置
3.自定义config,绑定
@ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource druidDataSource() {
return new DruidDataSource();
}
@Bean
public ServletRegistrationBean<StatViewServlet> a() {
ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>(new StatViewServlet(),"/druid/*");
HashMap<String,String> hashMap = new HashMap<>();
//增加配置
hashMap.put("loginUsername", "admin");//登录key 固定的loginUsername
hashMap.put("loginPassword", "123456");//登录密码 固定loginPassword
//允许谁可以访问
hashMap.put("allow", "localhost");
//禁止谁能访问
//hashMap.put("wjm", "192.168.23.12");
bean.setInitParameters(hashMap); //初始化参数
return bean;
}
4.输入localhost:8081/druid