前言
前提是在springboot上已经使用了druid,但是没有监控。因此怎么使用druid不在本文范围内,或者如果不是通过springboot使用druid的也不在本文范围内。
增加druid连接池监控
增加servlet
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import com.alibaba.druid.support.http.StatViewServlet;
@WebServlet(urlPatterns = "/druid/*",
initParams={
@WebInitParam(name="loginUsername",value="admin"),// 用户名
@WebInitParam(name="loginPassword",value="druid"),// 密码
@WebInitParam(name="resetEnable",value="false")// 禁用HTML页面上的“Reset All”功能
})
public class DruidServlet extends StatViewServlet {
private static final long serialVersionUID = 1L;
}
增加filter
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import com.alibaba.druid.support.http.WebStatFilter;
@WebFilter(filterName="druidWebStatFilter",urlPatterns="/*",
initParams={
@WebInitParam(name="exclusions",value="*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*")// 忽略资源
})
public class DruidFilter extends WebStatFilter {
}
增加ServletComponentScan
...
@ServletComponentScan
public class ServerApplication{
public static void main(String[] args) throws Exception {
SpringApplication.run(ServerApplication.class, args);
}
}