@SuppressWarnings("serial")
@WebServlet(urlPatterns = "/druid/*",
initParams = {
@WebInitParam(name = "allow", value = "127.0.0.1"),// IP白名单 (没有配置或者为空,则允许所有访问)
@WebInitParam(name = "deny", value = ""),// IP黑名单 (存在共同时,deny优先于allow)
@WebInitParam(name = "loginUsername", value = "root"),// 用户名
@WebInitParam(name = "loginPassword", value = "password"),// 密码
@WebInitParam(name = "resetEnable", value = "false")// 禁用HTML页面上的“Reset All”功能
})
public class DruidStatViewServlet extends StatViewServlet {
private static final long serialVersionUID = 1L;
}
Similar to the code above.
@WebInitParam(name = "allow", value = "127.0.0.1"),// IP白名单 (没有配置或者为空,则允许所有访问)
@WebInitParam(name = "deny", value = ""),// IP黑名单 (存在共同时,deny优先于allow)
@WebInitParam(name = "loginUsername", value = "root"),// 用户名
@WebInitParam(name = "loginPassword", value = "password"),// 密码
@WebInitParam(name = "resetEnable", value = "false")// 禁用HTML页面上的“Reset All”功能
How can these parameters be read and assigned from the configuration file?
Currently Spring Boot does not resolve the attribute values in @WebServlet in the Servlet 3.0 API. If the author needs it, you can define @Bean ServletRegistrationBean to get the value in Environment.
Why not write it in the configuration file?
The annotation is to save the configuration file. You use the annotation and you have to return to the configuration file. I don’t understand it
Choose one of the two annotations and configuration files. It depends on what you configure here is the druid monitoring servlet. The same content can be configured through web.xml. You can refer to the druid configuration document. Search Baidu, I won’t post the configuration file.