Java Code Examples for org.springframework.boot.web.servlet.ServletRegistrationBean#addInitParameter()

The following examples show how to use org.springframework.boot.web.servlet.ServletRegistrationBean#addInitParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DruidMonitorConfig.java    From spring-boot-shiro with Apache License 2.0 6 votes vote down vote up
/**
 * 注册ServletRegistrationBean
 * @return
 */
@Bean
public ServletRegistrationBean<StatViewServlet> registrationBean() {
    //org.springframework.boot.context.embedded.ServletRegistrationBean提供类的进行注册.
    ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");
    /** 初始化参数配置,initParams**/
    //白名单
    bean.addInitParameter("allow", "127.0.0.1");//多个ip逗号隔开
    //IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page.
    //bean.addInitParameter("deny", "192.168.1.110");
    //登录查看信息的账号密码.
    bean.addInitParameter("loginUsername", "admin");
    bean.addInitParameter("loginPassword", "123456");
    //是否能够重置数据.
    bean.addInitParameter("resetEnable", "false");
    return bean;
}
 
Example 2
Source File: DruidMonitorConfigurer.java    From mySpringBoot with Apache License 2.0 6 votes vote down vote up
/**
 * 注册ServletRegistrationBean
 * @return
 */
@Bean
public ServletRegistrationBean registrationBean() {
    ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
    /** 初始化参数配置,initParams**/
    //白名单多个ip逗号隔开
    bean.addInitParameter("allow", "127.0.0.1,192.168.0.102");
    //IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page.
    bean.addInitParameter("deny", "192.168.1.110");
    //登录查看信息的账号密码.
    bean.addInitParameter("loginUsername", "admin");
    bean.addInitParameter("loginPassword", "123456");
    //是否能够重置数据.
    bean.addInitParameter("resetEnable", "false");
    return bean;
}
 
Example 3
Source File: DruidServletConfiguration.java    From druid-spring-boot with Apache License 2.0 6 votes vote down vote up
/**
 * Druid 提供了一个 StatViewServlet 用于展示 Druid 的统计信息
 * 这个 StatViewServlet 的用途包括:
 *   1. 提供监控信息展示的 HTML 页面
 *   2. 提供监控信息的 JSON API
 */
@Bean
public ServletRegistrationBean druidStatViewServlet(DruidDataSourceProperties druidProperties) {
    log.debug("druid stat-view-servlet init...");
    DruidStatViewServletProperties properties = druidProperties.getStatViewServlet();
    ServletRegistrationBean registration = new ServletRegistrationBean(new StatViewServlet());
    registration.addUrlMappings(properties.getUrlMappings());
    if (!StringUtils.isEmpty(properties.getLoginUsername())) {
        registration.addInitParameter("loginUsername", properties.getLoginUsername());
    }
    if (!StringUtils.isEmpty(properties.getLoginPassword())) {
        registration.addInitParameter("loginPassword", properties.getLoginPassword());
    }
    if (!StringUtils.isEmpty(properties.getAllow())) {
        registration.addInitParameter("allow", properties.getAllow());
    }
    if (!StringUtils.isEmpty(properties.getDeny())) {
        registration.addInitParameter("deny", properties.getDeny());
    }
    registration.addInitParameter("resetEnable", Boolean.toString(properties.isResetEnable()));
    return registration;
}
 
Example 4
Source File: EmbeddedKeycloakConfig.java    From spring-security-oauth with MIT License 6 votes vote down vote up
@Bean
ServletRegistrationBean<HttpServlet30Dispatcher> keycloakJaxRsApplication(
		KeycloakServerProperties keycloakServerProperties, DataSource dataSource) throws Exception {

	mockJndiEnvironment(dataSource);
	EmbeddedKeycloakApplication.keycloakServerProperties = keycloakServerProperties;

	ServletRegistrationBean<HttpServlet30Dispatcher> servlet = new ServletRegistrationBean<>(
			new HttpServlet30Dispatcher());
	servlet.addInitParameter("javax.ws.rs.Application", EmbeddedKeycloakApplication.class.getName());
	servlet.addInitParameter(ResteasyContextParameters.RESTEASY_SERVLET_MAPPING_PREFIX,
			keycloakServerProperties.getContextPath());
	servlet.addInitParameter(ResteasyContextParameters.RESTEASY_USE_CONTAINER_FORM_PARAMS, "true");
	servlet.addUrlMappings(keycloakServerProperties.getContextPath() + "/*");
	servlet.setLoadOnStartup(1);
	servlet.setAsyncSupported(true);

	return servlet;
}
 
Example 5
Source File: DruidConfig.java    From kitty with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
     * 注册Servlet信息, 配置监控视图
     *
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    public ServletRegistrationBean<Servlet> druidServlet() {
        ServletRegistrationBean<Servlet> servletRegistrationBean = new ServletRegistrationBean<Servlet>(new StatViewServlet(), "/druid/*");

        //白名单:
//        servletRegistrationBean.addInitParameter("allow","127.0.0.1,139.196.87.48");
        //IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page.
        servletRegistrationBean.addInitParameter("deny","192.168.1.119");
        //登录查看信息的账号密码, 用于登录Druid监控后台
        servletRegistrationBean.addInitParameter("loginUsername", "admin");
        servletRegistrationBean.addInitParameter("loginPassword", "admin");
        //是否能够重置数据.
        servletRegistrationBean.addInitParameter("resetEnable", "true");
        return servletRegistrationBean;

    }
 
Example 6
Source File: EmbeddedKeycloakConfig.java    From spring-boot-keycloak-server-example with Apache License 2.0 6 votes vote down vote up
@Bean
ServletRegistrationBean<HttpServlet30Dispatcher> keycloakJaxRsApplication(SpringBootConfigProvider configProvider) {

    //FIXME: hack to propagate Spring Boot Properties to Keycloak Application
    EmbeddedKeycloakApplication.keycloakProperties = keycloakProperties;

    //FIXME: hack to propagate Spring Boot Properties to Keycloak Application
    EmbeddedKeycloakApplication.customProperties = customProperties;

    //FIXME: hack to propagate Spring Boot ConfigProvider to Keycloak Application
    EmbeddedKeycloakApplication.configProvider = configProvider;

    ServletRegistrationBean<HttpServlet30Dispatcher> servlet = new ServletRegistrationBean<>(new HttpServlet30Dispatcher());
    servlet.addInitParameter("javax.ws.rs.Application", EmbeddedKeycloakApplication.class.getName());
    String keycloakContextPath = customProperties.getServer().getContextPath();
    servlet.addInitParameter(ResteasyContextParameters.RESTEASY_SERVLET_MAPPING_PREFIX, keycloakContextPath);
    servlet.addInitParameter(ResteasyContextParameters.RESTEASY_USE_CONTAINER_FORM_PARAMS, "true");
    servlet.addUrlMappings(keycloakContextPath + "/*");
    servlet.setLoadOnStartup(1);
    servlet.setAsyncSupported(true);

    return servlet;
}
 
Example 7
Source File: EmbeddedKeycloakConfig.java    From spring-security-oauth with MIT License 6 votes vote down vote up
@Bean
ServletRegistrationBean<HttpServlet30Dispatcher> keycloakJaxRsApplication(KeycloakServerProperties keycloakServerProperties, DataSource dataSource) throws Exception {

    mockJndiEnvironment(dataSource);
    EmbeddedKeycloakApplication.keycloakServerProperties = keycloakServerProperties;

    ServletRegistrationBean<HttpServlet30Dispatcher> servlet = new ServletRegistrationBean<>(new HttpServlet30Dispatcher());
    servlet.addInitParameter("javax.ws.rs.Application", EmbeddedKeycloakApplication.class.getName());
    servlet.addInitParameter(ResteasyContextParameters.RESTEASY_SERVLET_MAPPING_PREFIX, keycloakServerProperties.getContextPath());
    servlet.addInitParameter(ResteasyContextParameters.RESTEASY_USE_CONTAINER_FORM_PARAMS, "true");
    servlet.addUrlMappings(keycloakServerProperties.getContextPath() + "/*");
    servlet.setLoadOnStartup(1);
    servlet.setAsyncSupported(true);

    return servlet;
}
 
Example 8
Source File: DruidConfiguration.java    From springBoot-study with Apache License 2.0 6 votes vote down vote up
@Bean
public ServletRegistrationBean druidStatViewServle() {
	//注册服务
	ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(
			new StatViewServlet(), "/druid/*");
	// 白名单(为空表示,所有的都可以访问,多个IP的时候用逗号隔开)
	servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
	// IP黑名单 (存在共同时,deny优先于allow) 
	servletRegistrationBean.addInitParameter("deny", "127.0.0.2");
	// 设置登录的用户名和密码
	servletRegistrationBean.addInitParameter("loginUsername", "pancm");
	servletRegistrationBean.addInitParameter("loginPassword", "123456");
	// 是否能够重置数据.
	servletRegistrationBean.addInitParameter("resetEnable", "false");
	return servletRegistrationBean;
}
 
Example 9
Source File: DruidConfig.java    From SpringBoot-Base-System with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 也可以通过继承StatViewServlet 使用@WebFilter实现
 * 
 * @time 2018年4月10日 下午4:59:57.
 * @version V1.0
 * @return ServletRegistrationBean
 */
@Bean
public ServletRegistrationBean statViewServle() {
	ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),
			"/druid/*");
	// 白名单:1
	servletRegistrationBean.addInitParameter("allow", "192.168.1.1,127.0.0.1");
	// IP黑名单 (存在共同时,deny优先于allow)
	// servletRegistrationBean.addInitParameter("deny", "192.168.1.100");
	// 登录查看信息的账号密码.
	// servletRegistrationBean.addInitParameter("loginUsername", "druid");
	// servletRegistrationBean.addInitParameter("loginPassword",
	// "druid123");
	// 是否能够重置数据.
	servletRegistrationBean.addInitParameter("resetEnable", "false");
	return servletRegistrationBean;
}
 
Example 10
Source File: WebRegistrationConfiguration.java    From EasyEE with MIT License 5 votes vote down vote up
/**
 * CKFinder Servlet
 * @return
 */
@Bean
public ServletRegistrationBean ckfinderConnectorServletRegistrationBean() {
	ServletRegistrationBean registrationBean = new ServletRegistrationBean();
	registrationBean.addInitParameter("XMLConfig", "/WEB-INF/ckfinder-config.xml");
	registrationBean.addInitParameter("debug", "false");
	registrationBean.setOrder(1);
	// Jars in "WEB-INF/lib/", please add to build path for development
	registrationBean.setServlet(new com.ckfinder.connector.ConnectorServlet());
	
	registrationBean.addUrlMappings("/staticresources/ckfinder/core/connector/java/connector.java");
	return registrationBean;
}
 
Example 11
Source File: DruidConfiguration.java    From bootshiro with MIT License 5 votes vote down vote up
@Bean
public ServletRegistrationBean druidServlet() {
    LOGGER.info("init Druid Servlet Configuration ");
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
    // IP白名单
    //("allow", "192.168.2.25,116.196.81.106,127.0.0.1");
    // IP黑名单(共同存在时,deny优先于allow)
    //("deny", "");
    //控制台管理用户
    servletRegistrationBean.addInitParameter("loginUsername", "admin");
    servletRegistrationBean.addInitParameter("loginPassword", "admin");
    //是否能够重置数据 禁用HTML页面上的“Reset All”功能
    servletRegistrationBean.addInitParameter("resetEnable", "false");
    return servletRegistrationBean;
}
 
Example 12
Source File: ExternalizedConfigurationWebApplicationBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean<DispatcherServlet> dispatcherServletRegistrationBean(ConfigurableEnvironment environment) {
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
    // 构建 DispatcherServlet 应用上下文
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    // 复用当前 ApplicationContext 的 ConfigurableEnvironment 对象
    context.setEnvironment(environment);
    // 设置 DispatcherServlet
    servletRegistrationBean.setServlet(new DispatcherServlet(context));
    // 设置 ServletConfig 初始化参数
    servletRegistrationBean.addInitParameter("my-servlet-name", "My DispatcherServlet");
    return servletRegistrationBean;
}
 
Example 13
Source File: DruidConfiguration.java    From LazyREST with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 14
Source File: MockApplication.java    From AuTe-Framework with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean wiremockAdminHandlerBean() {
    ServletRegistrationBean bean = new ServletRegistrationBean(new WireMockHandlerDispatchingServlet(), "/__admin/*");
    bean.addInitParameter("RequestHandlerClass", AdminRequestHandler.class.getName());
    bean.setLoadOnStartup(1);
    bean.setName("wiremockAdmin");
    return bean;
}
 
Example 15
Source File: DruidDataSourceConfiguration.java    From NetworkDisk_Storage with GNU General Public License v2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean<StatViewServlet> druidServlet() {
	ServletRegistrationBean<StatViewServlet> servletRegistrationBean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");
	servletRegistrationBean.addInitParameter("allow", "");
	servletRegistrationBean.addInitParameter("deny", "192.168.1.100");
	servletRegistrationBean.addInitParameter("loginUsername", "727Pan");
	servletRegistrationBean.addInitParameter("loginPassword", "727Pan&quhailong");
	servletRegistrationBean.addInitParameter("resetEnable", "false");
	return servletRegistrationBean;
}
 
Example 16
Source File: DataSourceAutoConfiguration.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean druidServlet(DruidProperties prop) {
	ServletRegistrationBean reg = new ServletRegistrationBean();
	reg.setServlet(new StatViewServlet());
	reg.addUrlMappings("/druid/*");
	reg.addInitParameter("loginUsername", prop.getWebLoginUsername());
	reg.addInitParameter("loginPassword", prop.getWebLoginPassword());
	reg.addInitParameter("logSlowSql", prop.getLogSlowSql());
	return reg;
}
 
Example 17
Source File: DruidConfiguration.java    From elephant with Apache License 2.0 5 votes vote down vote up
@Bean
    public ServletRegistrationBean druidServlet() {
        logger.info("init Druid Servlet Configuration ");
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
        // IP白名单
        servletRegistrationBean.addInitParameter("allow", "");
        // IP黑名单(共同存在时,deny优先于allow)
//        servletRegistrationBean.addInitParameter("deny", "");
        //控制台管理用户
        servletRegistrationBean.addInitParameter("loginUsername", "admin");
        servletRegistrationBean.addInitParameter("loginPassword", "admin");
        //是否能够重置数据 禁用HTML页面上的“Reset All”功能
        servletRegistrationBean.addInitParameter("resetEnable", "false");
        return servletRegistrationBean;
    }
 
Example 18
Source File: MqConfig.java    From pmq with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean druidStatViewServle() {

	// org.springframework.boot.context.embedded.ServletRegistrationBean提供类的进行注册.

	ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),
			"/druid/*");

	// 添加初始化参数:initParams
	//
	// //白名单:
	//
	// servletRegistrationBean.addInitParameter("allow","127.0.0.1");
	//
	// //IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not
	// permitted to view this page.
	//
	// servletRegistrationBean.addInitParameter("deny","192.168.1.73");

	// 登录查看信息的账号密码.

	servletRegistrationBean.addInitParameter("loginUsername", "admin");

	servletRegistrationBean.addInitParameter("loginPassword", "admin");

	// 是否能够重置数据.

	servletRegistrationBean.addInitParameter("resetEnable", "false");

	return servletRegistrationBean;

}
 
Example 19
Source File: ShiroConfig.java    From SpringBootBucket with MIT License 5 votes vote down vote up
@Bean
    public ServletRegistrationBean kaptchaServlet() {
        ServletRegistrationBean servlet = new ServletRegistrationBean(new KaptchaServlet(), "/kaptcha.jpg");
        servlet.addInitParameter(Constants.KAPTCHA_SESSION_CONFIG_KEY, Constants.KAPTCHA_SESSION_KEY);//session key
        servlet.addInitParameter(Constants.KAPTCHA_TEXTPRODUCER_FONT_SIZE, "50");//字体大小
        servlet.addInitParameter(Constants.KAPTCHA_BORDER, "no");
        servlet.addInitParameter(Constants.KAPTCHA_BORDER_COLOR, "105,179,90");
        servlet.addInitParameter(Constants.KAPTCHA_TEXTPRODUCER_FONT_SIZE, "45");
        servlet.addInitParameter(Constants.KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4");
        servlet.addInitParameter(Constants.KAPTCHA_TEXTPRODUCER_FONT_NAMES, "宋体,楷体,微软雅黑");
        servlet.addInitParameter(Constants.KAPTCHA_TEXTPRODUCER_FONT_COLOR, "blue");
        servlet.addInitParameter(Constants.KAPTCHA_IMAGE_WIDTH, "125");
        servlet.addInitParameter(Constants.KAPTCHA_IMAGE_HEIGHT, "60");
        //可以设置很多属性,具体看com.google.code.kaptcha.Constants
//		kaptcha.border  是否有边框  默认为true  我们可以自己设置yes,no
//		kaptcha.border.color   边框颜色   默认为Color.BLACK
//		kaptcha.border.thickness  边框粗细度  默认为1
//		kaptcha.producer.impl   验证码生成器  默认为DefaultKaptcha
//		kaptcha.textproducer.impl   验证码文本生成器  默认为DefaultTextCreator
//		kaptcha.textproducer.char.string   验证码文本字符内容范围  默认为abcde2345678gfynmnpwx
//		kaptcha.textproducer.char.length   验证码文本字符长度  默认为5
//		kaptcha.textproducer.font.names    验证码文本字体样式  默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize)
//		kaptcha.textproducer.font.size   验证码文本字符大小  默认为40
//		kaptcha.textproducer.font.color  验证码文本字符颜色  默认为Color.BLACK
//		kaptcha.textproducer.char.space  验证码文本字符间距  默认为2
//		kaptcha.noise.impl    验证码噪点生成对象  默认为DefaultNoise
//		kaptcha.noise.color   验证码噪点颜色   默认为Color.BLACK
//		kaptcha.obscurificator.impl   验证码样式引擎  默认为WaterRipple
//		kaptcha.word.impl   验证码文本字符渲染   默认为DefaultWordRenderer
//		kaptcha.background.impl   验证码背景生成器   默认为DefaultBackground
//		kaptcha.background.clear.from   验证码背景颜色渐进   默认为Color.LIGHT_GRAY
//		kaptcha.background.clear.to   验证码背景颜色渐进   默认为Color.WHITE
//		kaptcha.image.width   验证码图片宽度  默认为200
//		kaptcha.image.height  验证码图片高度  默认为50
        return servlet;
    }
 
Example 20
Source File: WebRegistrationConfiguration.java    From EasyEE with MIT License 5 votes vote down vote up
/**
 * CKFinder Servlet
 * @return
 */
@Bean
public ServletRegistrationBean ckfinderConnectorServletRegistrationBean() {
	ServletRegistrationBean registrationBean = new ServletRegistrationBean();
	registrationBean.addInitParameter("XMLConfig", "/WEB-INF/ckfinder-config.xml");
	registrationBean.addInitParameter("debug", "false");
	registrationBean.setOrder(1);
	// Jars in "WEB-INF/lib/", please add to build path for development
	registrationBean.setServlet(new com.ckfinder.connector.ConnectorServlet());
	
	registrationBean.addUrlMappings("/staticresources/ckfinder/core/connector/java/connector.java");
	return registrationBean;
}