java - spring annotation dynamic parameters
给我你的怀抱
给我你的怀抱 2017-05-27 17:40:04
0
3
751
@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?

给我你的怀抱
给我你的怀抱

reply all(3)
PHPzhong

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!