Springboot使用Druid后台监控

Springboot使用Druid后台监控

1.pom加入依赖

<!-- Druid -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.1.21</version>
		</dependency>

2.yml中配置

在这里插入图片描述

3.自定义config,绑定

	//绑定到yml
	@ConfigurationProperties(prefix = "spring.datasource")
	@Bean
	public DataSource druidDataSource() {
		return new DruidDataSource();
	}
	
	
	/**
	 * http://localhost:8081/druid 进入
	 */
	//后台监控
	@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

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只小小狗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值