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

The following examples show how to use org.springframework.boot.web.servlet.ServletRegistrationBean#addUrlMappings() . 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: 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 3
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 4
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;
}
 
Example 5
Source File: Application.java    From blog-sample with Apache License 2.0 5 votes vote down vote up
/**
 * 注入验证码servlet
 */
@Bean
public ServletRegistrationBean indexServletRegistration() {
    ServletRegistrationBean registration = new ServletRegistrationBean(new VerifyServlet());
    registration.addUrlMappings("/getVerifyCode");
    return registration;
}
 
Example 6
Source File: WebConfig.java    From Guns with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * druidServlet注册
 */
@Bean
public ServletRegistrationBean druidServletRegistration() {
    ServletRegistrationBean registration = new ServletRegistrationBean(new StatViewServlet());
    registration.addUrlMappings("/druid/*");
    return registration;
}
 
Example 7
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 8
Source File: OrderApplication.java    From code with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean getServlet(){
    HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
    ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
    registrationBean.setLoadOnStartup(1);
    registrationBean.addUrlMappings("/hystrix.stream");/*/actuator/hystrix.stream*/
    registrationBean.setName("HystrixMetricsStreamServlet");
    return registrationBean;
}
 
Example 9
Source File: WebConfig.java    From MeetingFilm with Apache License 2.0 5 votes vote down vote up
/**
 * druidServlet注册
 */
@Bean
public ServletRegistrationBean druidServletRegistration() {
    ServletRegistrationBean registration = new ServletRegistrationBean(new StatViewServlet());
    registration.addUrlMappings("/druid/*");
    return registration;
}
 
Example 10
Source File: HystrixServlet.java    From springcloud-study with Apache License 2.0 5 votes vote down vote up
/**
	 *  指定 hystrix 的路径
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
//	@Bean
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }
 
Example 11
Source File: ServiceRibbonApplication.java    From SpringCloud-Finchley-samples with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean getServlet() {
	HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
	ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
	registrationBean.setLoadOnStartup(1);
	registrationBean.addUrlMappings("/hystrix.stream");
	registrationBean.setName("HystrixMetricsStreamServlet");
	return registrationBean;

}
 
Example 12
Source File: HystrixDashboardConfig.java    From cloud-template with MIT License 5 votes vote down vote up
@Bean
public ServletRegistrationBean getServlet() {
    HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
    ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
    registrationBean.setLoadOnStartup(1);
    registrationBean.addUrlMappings("/hystrix.stream");
    registrationBean.setName("HystrixMetricsStreamServlet");
    return registrationBean;
}
 
Example 13
Source File: DruidDataSourceConfig.java    From easyweb 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 14
Source File: GenericTestProxyContainer.java    From odo with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean dispatcherRegistration() {
    ServletRegistrationBean registration = new ServletRegistrationBean(new TestHandler());
    registration.addUrlMappings("/*");

    return registration;
}
 
Example 15
Source File: HystrixMappingAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean
ServletRegistrationBean servletRegistrationBean(HystrixMappingConfiguration config) {
    ServletRegistrationBean mapping = new ServletRegistrationBean();
    mapping.setServlet(new HystrixEventStreamServlet());
    mapping.addUrlMappings(config.getPath());
    mapping.setName(config.getServletName());

    return mapping;
}
 
Example 16
Source File: ServiceAuthApplicationMain.java    From e with Apache License 2.0 4 votes vote down vote up
@Bean
public ServletRegistrationBean h2servletRegistration() {
    ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet());
    registration.addUrlMappings("/console/*");
    return registration;
}
 
Example 17
Source File: CalendarApplication.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
@Bean
public ServletRegistrationBean h2ConsoleServletRegistration() {
    ServletRegistrationBean bean = new ServletRegistrationBean(new org.h2.server.web.WebServlet());
    bean.addUrlMappings("/admin/h2/*");
    return bean;
}
 
Example 18
Source File: H2WebConsoleConfiguration.java    From binance-marketmaker with The Unlicense 4 votes vote down vote up
@Bean
ServletRegistrationBean h2servletRegistration(){
    ServletRegistrationBean registrationBean = new ServletRegistrationBean( new WebServlet());
    registrationBean.addUrlMappings("/console/*");
    return registrationBean;
}
 
Example 19
Source File: WebConfiguration.java    From research-graphql with MIT License 4 votes vote down vote up
@Bean
ServletRegistrationBean h2servletRegistration(){
    ServletRegistrationBean registrationBean = new ServletRegistrationBean( new WebServlet());
    registrationBean.addUrlMappings("/h2/console/*");
    return registrationBean;
}
 
Example 20
Source File: H2DbConfiguration.java    From java-microservice with MIT License 4 votes vote down vote up
@Bean
ServletRegistrationBean h2servletRegistration(){
    ServletRegistrationBean registrationBean = new ServletRegistrationBean( new WebServlet());
    registrationBean.addUrlMappings("/console/*");
    return registrationBean;
}