@SuppressWarnings("serial")
@WebServlet(urlPatterns = "/druid/*",
initParams = {
@WebInitParam(name = "allow", value = "127.0.0.1"),// IP白名單 (沒(méi)有配置或者為空,則允許所有訪問(wèn))
@WebInitParam(name = "deny", value = ""),// IP黑名單 (存在共同時(shí),deny優(yōu)先于allow)
@WebInitParam(name = "loginUsername", value = "root"),// 用戶名
@WebInitParam(name = "loginPassword", value = "password"),// 密碼
@WebInitParam(name = "resetEnable", value = "false")// 禁用HTML頁(yè)面上的“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白名單 (沒(méi)有配置或者為空,則允許所有訪問(wèn))
@WebInitParam(name = "deny", value = ""),// IP黑名單 (存在共同時(shí),deny優(yōu)先于allow)
@WebInitParam(name = "loginUsername", value = "root"),// 用戶名
@WebInitParam(name = "loginPassword", value = "password"),// 密碼
@WebInitParam(name = "resetEnable", value = "false")// 禁用HTML頁(yè)面上的“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?
<init-param>
<param-name>aaa</param-name>
<param-value>
bb
</param-value>
</init-param>
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.