Home  >  Q&A  >  body text

java - spring annotation dynamic parameters

@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?

给我你的怀抱给我你的怀抱2702 days ago748

reply all(3)I'll reply

  • PHPz

    PHPz2017-05-27 17:42:04

    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.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-27 17:42:04

    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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-27 17:42:04

    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.

    reply
    0
  • Cancelreply