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

The following examples show how to use org.springframework.boot.web.servlet.ServletRegistrationBean#setServlet() . 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: DruidConfig.java    From springboot-learn with MIT License 6 votes vote down vote up
@Bean
public ServletRegistrationBean druidServlet() {
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
    servletRegistrationBean.setServlet(new StatViewServlet());
    servletRegistrationBean.addUrlMappings("/druid/*");
    Map<String, String> initParameters = new HashMap<>();
    initParameters.put("resetEnable", "false"); //禁用HTML页面上的“Rest All”功能
    initParameters.put("allow", "");  //ip白名单(没有配置或者为空,则允许所有访问)
    initParameters.put("loginUsername", "admin");  //++监控页面登录用户名
    initParameters.put("loginPassword", "admin");  //++监控页面登录用户密码
    initParameters.put("deny", ""); //ip黑名单
    initParameters.put("slowSqlMillis", "200");//执行时间大于200毫秒的都是慢sql

    //如果某个ip同时存在,deny优先于allow
    servletRegistrationBean.setInitParameters(initParameters);
    return servletRegistrationBean;
}
 
Example 2
Source File: DruidConfig.java    From AthenaServing with Apache License 2.0 6 votes vote down vote up
/**
 * 注册ServletRegistrationBean
 *
 * @return
 */
@Bean
public ServletRegistrationBean druidServlet() {
    ServletRegistrationBean reg = new ServletRegistrationBean();
    reg.setServlet(new StatViewServlet());
    reg.addUrlMappings("/druid/*");
    reg.addInitParameter("loginUsername", "sctang2");
    reg.addInitParameter("loginPassword", "2017007476");
    reg.addInitParameter("allow", propUtil.IP);
    reg.addInitParameter("deny", "");
    reg.addInitParameter("resetEnable", "false");
    reg.addInitParameter("mergeSql", "true");
    reg.addInitParameter("slowSqlMillis", "10");
    reg.addInitParameter("logSlowSql", "true");
    return reg;
}
 
Example 3
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 4
Source File: FunktionRouteBuilder.java    From funktion-connectors with Apache License 2.0 5 votes vote down vote up
@Bean
ServletRegistrationBean camelServlet() {
    // use a @Bean to register the Camel servlet which we need to do
    // because we want to use the camel-servlet component for the Camel REST service
    ServletRegistrationBean mapping = new ServletRegistrationBean();
    mapping.setName("CamelServlet");
    mapping.setLoadOnStartup(1);
    mapping.setServlet(new CamelHttpTransportServlet());
    mapping.addUrlMappings("/camel/*");
    return mapping;
}
 
Example 5
Source File: MonitorAutoconfiguration.java    From saluki with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean registration(HystrixMetricsStreamServlet servlet) {
    ServletRegistrationBean registrationBean = new ServletRegistrationBean();
    registrationBean.setServlet(servlet);
    registrationBean.setEnabled(true);
    registrationBean.addUrlMappings("/hystrix.stream");
    return registrationBean;
}
 
Example 6
Source File: WebhookServletAutoConfiguration.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean<CamelHttpTransportServlet> servletRegistrationBean() {
    ServletRegistrationBean<CamelHttpTransportServlet> mapping = new ServletRegistrationBean<>();
    mapping.setServlet(new CamelHttpTransportServlet());
    mapping.addUrlMappings("/webhook/*");
    mapping.setName("CamelServlet");
    mapping.setLoadOnStartup(1);

    return mapping;
}
 
Example 7
Source File: JavametricsCodewindSpringConfigurer.java    From javametrics with Apache License 2.0 5 votes vote down vote up
@Bean
ServletRegistrationBean JavametricsCodewindSpringServletRegistration () {
	ServletRegistrationBean srb = new ServletRegistrationBean();
	srb.setServlet(new WebPage());
	srb.setUrlMappings(Arrays.asList("/metrics/codewind"));
	return srb;
}
 
Example 8
Source File: DruidConfig.java    From renren-fast with GNU General Public License v3.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean druidServlet() {
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
    servletRegistrationBean.setServlet(new StatViewServlet());
    servletRegistrationBean.addUrlMappings("/druid/*");
    return servletRegistrationBean;
}
 
Example 9
Source File: WebConfig.java    From platform with Apache License 2.0 5 votes vote down vote up
/**
 * StatViewServlet
 *
 * @return {@link StatViewServlet}
 */
@Bean
@ConditionalOnWebApplication
public ServletRegistrationBean<StatViewServlet> statViewServlet() {
    ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>();
    bean.setServlet(new StatViewServlet());
    bean.addUrlMappings("/druid/*");
    return bean;
}
 
Example 10
Source File: ActivitiUIApplication.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean appDispatcher() {
    DispatcherServlet api = new DispatcherServlet();
    api.setContextClass(AnnotationConfigWebApplicationContext.class);
    api.setContextConfigLocation(AppDispatcherServletConfiguration.class.getName());
    ServletRegistrationBean registrationBean = new ServletRegistrationBean();
    registrationBean.setServlet(api);
    registrationBean.addUrlMappings("/app/*"); // app下面的所有内容都访问到这里
    registrationBean.setLoadOnStartup(1);
    registrationBean.setAsyncSupported(true);
    registrationBean.setName("app"); // 不能重复,重复则以最后一个设置的为准

    return registrationBean;
}
 
Example 11
Source File: ActivitiUIApplication.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean apiDispatcher() {
    DispatcherServlet api = new DispatcherServlet();
    api.setContextClass(AnnotationConfigWebApplicationContext.class);
    api.setContextConfigLocation(ApiDispatcherServletConfiguration.class.getName());
    ServletRegistrationBean registrationBean = new ServletRegistrationBean();
    registrationBean.setServlet(api);
    registrationBean.addUrlMappings("/api/*"); // api下面的所有内容都访问到这里
    registrationBean.setLoadOnStartup(1);
    registrationBean.setAsyncSupported(true);
    registrationBean.setName("api"); // 不能重复,重复则以最后一个设置的为准

    return registrationBean;
}
 
Example 12
Source File: AppConfig.java    From OpenCue with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean jobLaunchServlet() {
    ServletRegistrationBean b = new ServletRegistrationBean();
    b.addUrlMappings("/launch");
    b.addInitParameter("contextConfigLocation", "classpath:conf/spring/jobLaunchServlet-servlet.xml");
    b.setServlet(new JobLaunchServlet());
    return b;
}
 
Example 13
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 14
Source File: WebhookServletAutoConfiguration.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Bean
ServletRegistrationBean servletRegistrationBean() {
    ServletRegistrationBean mapping = new ServletRegistrationBean();
    mapping.setServlet(new CamelHttpTransportServlet());
    mapping.addUrlMappings("/webhook/*");
    mapping.setName("CamelServlet");
    mapping.setLoadOnStartup(1);

    return mapping;
}
 
Example 15
Source File: WebServiceConfig.java    From freeacs with MIT License 5 votes vote down vote up
@Bean
public ServletRegistrationBean<Monitor> monitor() {
  ServletRegistrationBean<Monitor> srb = new ServletRegistrationBean<>();
  srb.setServlet(new Monitor());
  srb.setUrlMappings(Collections.singletonList("/ok"));
  return srb;
}
 
Example 16
Source File: DruidStatConfig.java    From frpMgr with MIT License 5 votes vote down vote up
/**
 * 注册DruidServlet
 */
@Bean
public ServletRegistrationBean druidServlet() {
	ServletRegistrationBean bean = new ServletRegistrationBean();
	bean.setServlet(new StatViewServlet());
	bean.addUrlMappings("/druid/*");
	return bean;
}
 
Example 17
Source File: DruidConfig.java    From spring-boot-demo-all with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean druidServlet() {
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
    servletRegistrationBean.setServlet(new StatViewServlet());
    servletRegistrationBean.addUrlMappings("/druid/*");
    Map<String, String> initParameters = new HashMap<String, String>();
    // initParameters.put("loginUsername", "druid");// 用户名
    // initParameters.put("loginPassword", "druid");// 密码
    initParameters.put("resetEnable", "false");// 禁用HTML页面上的“Reset All”功能
    initParameters.put("allow", "127.0.0.1"); // IP白名单 (没有配置或者为空,则允许所有访问)
    // initParameters.put("deny", "192.168.20.38");// IP黑名单
    // (存在共同时,deny优先于allow)
    servletRegistrationBean.setInitParameters(initParameters);
    return servletRegistrationBean;
}
 
Example 18
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 19
Source File: EcssentDatabaseConfig.java    From maintain with MIT License 5 votes vote down vote up
@Bean
public ServletRegistrationBean druidServlet() {
	ServletRegistrationBean reg = new ServletRegistrationBean();
	reg.setServlet(new StatViewServlet());
	reg.addUrlMappings("/druid/*");
	// reg.addInitParameter("allow", "127.0.0.1");
	// reg.addInitParameter("deny","");
	reg.addInitParameter("loginUsername", "admin");
	reg.addInitParameter("loginPassword", "admin");
	return reg;
}
 
Example 20
Source File: SmartDruidDataSourceConfig.java    From smart-admin with MIT License 5 votes vote down vote up
@Bean
public ServletRegistrationBean druidServlet() {
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
    servletRegistrationBean.setServlet(new StatViewServlet());
    servletRegistrationBean.addUrlMappings("/druid/*");
    Map<String, String> initParameters = new HashMap<String, String>();
    //不设置用户名密码可以直接通过druid/index.html访问
    if (druidLoginEnable) {
        initParameters.put("loginUsername", druidUserName);
        initParameters.put("loginPassword", druidPassword);
    }
    initParameters.put("resetEnable", "false");
    servletRegistrationBean.setInitParameters(initParameters);
    return servletRegistrationBean;
}