Search in sources :

Example 6 with StatViewServlet

use of com.alibaba.druid.support.http.StatViewServlet in project springboot_op by SnailFastGo.

the class DruidConfiguration method statViewServlet.

@Bean
public ServletRegistrationBean statViewServlet() {
    // 创建servlet注册实体
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
    // 设置ip白名单
    servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
    // 设置ip黑名单,如果allow与deny共同存在时,deny优先于allow
    servletRegistrationBean.addInitParameter("deny", "192.168.0.19");
    // 设置控制台管理用户
    servletRegistrationBean.addInitParameter("loginUsername", "druid");
    servletRegistrationBean.addInitParameter("loginPassword", "123456");
    // 是否可以重置数据
    servletRegistrationBean.addInitParameter("resetEnable", "false");
    return servletRegistrationBean;
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 7 with StatViewServlet

use of com.alibaba.druid.support.http.StatViewServlet in project druid by alibaba.

the class StatViewServletTest_resetEnable method test_resetEnable_none.

public void test_resetEnable_none() throws Exception {
    Assert.assertTrue(DruidStatService.getInstance().isResetEnable());
    MockServletConfig servletConfig = new MockServletConfig();
    StatViewServlet servlet = new StatViewServlet();
    servlet.init(servletConfig);
    Assert.assertTrue(DruidStatService.getInstance().isResetEnable());
}
Also used : MockServletConfig(org.springframework.mock.web.MockServletConfig) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet)

Example 8 with StatViewServlet

use of com.alibaba.druid.support.http.StatViewServlet in project druid by alibaba.

the class StatViewServletTest_resetEnable method test_resetEnable_false.

public void test_resetEnable_false() throws Exception {
    Assert.assertTrue(DruidStatService.getInstance().isResetEnable());
    MockServletConfig servletConfig = new MockServletConfig();
    servletConfig.addInitParameter(StatViewServlet.PARAM_NAME_RESET_ENABLE, "false");
    StatViewServlet servlet = new StatViewServlet();
    servlet.init(servletConfig);
    Assert.assertFalse(DruidStatService.getInstance().isResetEnable());
}
Also used : MockServletConfig(org.springframework.mock.web.MockServletConfig) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet)

Example 9 with StatViewServlet

use of com.alibaba.druid.support.http.StatViewServlet in project druid by alibaba.

the class StatViewServletTest_resetEnable method test_resetEnable_error.

public void test_resetEnable_error() throws Exception {
    Assert.assertTrue(DruidStatService.getInstance().isResetEnable());
    MockServletConfig servletConfig = new MockServletConfig();
    servletConfig.addInitParameter(StatViewServlet.PARAM_NAME_RESET_ENABLE, "xxx");
    StatViewServlet servlet = new StatViewServlet();
    servlet.init(servletConfig);
    Assert.assertFalse(DruidStatService.getInstance().isResetEnable());
}
Also used : MockServletConfig(org.springframework.mock.web.MockServletConfig) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet)

Example 10 with StatViewServlet

use of com.alibaba.druid.support.http.StatViewServlet in project druid by alibaba.

the class StatViewServletTest_resetEnable method test_resetEnable_empty.

public void test_resetEnable_empty() throws Exception {
    Assert.assertTrue(DruidStatService.getInstance().isResetEnable());
    MockServletConfig servletConfig = new MockServletConfig();
    servletConfig.addInitParameter(StatViewServlet.PARAM_NAME_RESET_ENABLE, "");
    StatViewServlet servlet = new StatViewServlet();
    servlet.init(servletConfig);
    Assert.assertTrue(DruidStatService.getInstance().isResetEnable());
}
Also used : MockServletConfig(org.springframework.mock.web.MockServletConfig) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet)

Aggregations

StatViewServlet (com.alibaba.druid.support.http.StatViewServlet)23 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)13 Bean (org.springframework.context.annotation.Bean)13 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)11 MockServletConfig (org.springframework.mock.web.MockServletConfig)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 HashMap (java.util.HashMap)2 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)2 DruidStatProperties (com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties)1 ServletListenerRegistrationBean (org.springframework.boot.web.servlet.ServletListenerRegistrationBean)1