當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletRegistrationBean類代碼示例

本文整理匯總了Java中org.springframework.boot.web.servlet.ServletRegistrationBean的典型用法代碼示例。如果您正苦於以下問題:Java ServletRegistrationBean類的具體用法?Java ServletRegistrationBean怎麽用?Java ServletRegistrationBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ServletRegistrationBean類屬於org.springframework.boot.web.servlet包,在下文中一共展示了ServletRegistrationBean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: camelServlet

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
@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;
}
 
開發者ID:funktionio,項目名稱:funktion-connectors,代碼行數:12,代碼來源:FunktionRouteBuilder.java

示例2: registrationBean

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
/**
 * 注冊ServletRegistrationBean
 * @return
 */
@Bean
public ServletRegistrationBean registrationBean() {
  ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
  /** 初始化參數配置,initParams**/
  //白名單
  bean.addInitParameter("allow", "127.0.0.1");
  //IP黑名單 (存在共同時,deny優先於allow) : 如果滿足deny的話提示:Sorry, you are not permitted to view this page.
  bean.addInitParameter("deny", "192.168.1.73");
  //登錄查看信息的賬號密碼.
  bean.addInitParameter("loginUsername", "admin");
  bean.addInitParameter("loginPassword", "admin");
  //是否能夠重置數據.
  bean.addInitParameter("resetEnable", "false");
  return bean;
}
 
開發者ID:Zigin,項目名稱:MonitorPlatform,代碼行數:20,代碼來源:DruidConfiguration.java

示例3: camelServlet

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
@Bean
ServletRegistrationBean camelServlet() {
    // TODO: Camel 2.19 should support this OOTB
    // 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);
    // CamelHttpTransportServlet is the name of the Camel servlet to use
    mapping.setServlet(new CamelHttpTransportServlet());
    mapping.addUrlMappings("/api/*");
    return mapping;
}
 
開發者ID:abouchama,項目名稱:camel-springboot-rest-ose,代碼行數:14,代碼來源:route.java

示例4: servletRegistrationBean

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
/**
 * Druid 提供了一個 StatViewServlet 用於展示 Druid 的統計信息
 * 這個 StatViewServlet 的用途包括:
 *   1. 提供監控信息展示的 HTML 頁麵
 *   2. 提供監控信息的 JSON API
 */
@Bean
public ServletRegistrationBean servletRegistrationBean(DruidDataSourceProperties druidDataSourceProperties) {
    log.debug("druid stat-view-servlet init...");
    DruidStatViewServletProperties properties = druidDataSourceProperties.getStatViewServlet();
    ServletRegistrationBean registration = new ServletRegistrationBean();
    StatViewServlet statViewServlet = new StatViewServlet();
    registration.setServlet(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;
}
 
開發者ID:drtrang,項目名稱:druid-spring-boot,代碼行數:30,代碼來源:DruidServletConfiguration.java

示例5: druidServlet

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
@Bean
@ConfigurationProperties(DruidServletProperties.DRUID_SERVLET_PREFIX)
public ServletRegistrationBean druidServlet(DruidServletProperties properties) {
    ServletRegistrationBean reg = new ServletRegistrationBean();
    reg.setServlet(new StatViewServlet());
    reg.addUrlMappings(properties.getUrlMappings());
    if(properties.getAllow() !=null){
        reg.addInitParameter("allow", properties.getAllow());  // IP白名單 (沒有配置或者為空,則允許所有訪問)
    }
    if(properties.getDeny() !=null){
        reg.addInitParameter("deny", properties.getDeny()); //IP黑名單 (存在共同時,deny優先於allow)
    }
    if(properties.getLoginUsername() !=null){
        reg.addInitParameter("loginUsername", properties.getLoginUsername()); //用戶名
    }
    if(properties.getLoginPassword() !=null){
        reg.addInitParameter("loginPassword", properties.getLoginPassword()); // 密碼
    }
    if(properties.getResetEnable() !=null){
        reg.addInitParameter("resetEnable", properties.getResetEnable().toString());// 禁用HTML頁麵上的“Reset All”功能
    }
    return reg;
}
 
開發者ID:cuisongliu,項目名稱:druid-boot-starter,代碼行數:24,代碼來源:DruidServletAutoConfiguration.java

示例6: druidStatViewServlet

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
/**
 * 數據源監控注冊一個StatViewServlet
 *
 * @return
 */
@Bean
public ServletRegistrationBean druidStatViewServlet(){
    //注冊監控地址
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*");

    //白名單
    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","123456");
    //是否能夠重置數據.
    servletRegistrationBean.addInitParameter("resetEnable","false");
    return servletRegistrationBean;
}
 
開發者ID:hulvyou,項目名稱:spring-cloud-template,代碼行數:22,代碼來源:DruidConfig.java

示例7: jerseyServletRegistration

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
@Bean
public ServletRegistrationBean jerseyServletRegistration(
    JerseyProperties jerseyProperties, ResourceConfig config) {

    ServletRegistrationBean registration = new ServletRegistrationBean(
        new ServletContainer(config));

    for (Map.Entry<String, String> entry : jerseyProperties.getInit().entrySet()) {
        registration.addInitParameter(entry.getKey(), entry.getValue());
    }

    registration.addUrlMappings("/" +
        (StringUtils.isEmpty(lyreProperties.getApplicationPath()) ? "api" : lyreProperties.getApplicationPath())
        + "/*");
    registration.setName(APIx.class.getName());
    registration.setLoadOnStartup(1);
    return registration;

}
 
開發者ID:groovylabs,項目名稱:lyre,代碼行數:20,代碼來源:Lyre.java

示例8: registrationBean

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
/**
 * 注冊ServletRegistrationBean
 * @return
 */
@Bean
public ServletRegistrationBean registrationBean() {
    ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
    /** 初始化參數配置,initParams**/
    //白名單
    bean.addInitParameter("allow", "127.0.0.1");
    //IP黑名單 (存在共同時,deny優先於allow) : 如果滿足deny的話提示:Sorry, you are not permitted to view this page.
    bean.addInitParameter("deny", "192.168.1.73");
    //登錄查看信息的賬號密碼.
    bean.addInitParameter("loginUsername", "admin2");
    bean.addInitParameter("loginPassword", "123");
    //是否能夠重置數據.
    bean.addInitParameter("resetEnable", "false");
    return bean;
}
 
開發者ID:finefuture,項目名稱:data-migration,代碼行數:20,代碼來源:DruidConfiguration.java

示例9: registerProxyServlet

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
/**
 * Configures a custom jetty http proxy servlet based on <b>oneops.proxy.enabled</b>
 * config property. The proxy configuration is done on the <b>application.yaml</b> file.
 *
 * @param config OneOps config
 * @return {@link ServletRegistrationBean}
 */
@Bean
@ConditionalOnProperty("oneops.proxy.enabled")
public ServletRegistrationBean registerProxyServlet(OneOpsConfig config) {
    log.info("OneOps Http Proxy is enabled.");
    OneOpsConfig.Proxy proxyCfg = config.getProxy();

    Map<String, String> initParams = new HashMap<>();
    initParams.put(proxyTo.name(), proxyCfg.getProxyTo());
    initParams.put(prefix.name(), proxyCfg.getPrefix());
    initParams.put(viaHost.name(), proxyCfg.getViaHost());
    initParams.put(trustAll.name(), String.valueOf(proxyCfg.isTrustAll()));
    initParams.put(xAuthHeader.name(), config.getAuth().getHeader());

    ServletRegistrationBean servletBean = new ServletRegistrationBean(new ProxyServlet(), proxyCfg.getPrefix() + "/*");
    servletBean.setName("OneOps Proxy Servlet");
    servletBean.setInitParameters(initParams);
    servletBean.setAsyncSupported(true);
    log.info("Configured OneOps proxy servlet with mapping: " + proxyCfg.getPrefix());
    return servletBean;
}
 
開發者ID:oneops,項目名稱:secrets-proxy,代碼行數:28,代碼來源:EmbeddedServerConfig.java

示例10: messageDispatcherServlet

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
@Bean
public ServletRegistrationBean messageDispatcherServlet(
		ApplicationContext applicationContext) {
	MessageDispatcherServlet servlet = new MessageDispatcherServlet();
	servlet.setApplicationContext(applicationContext);
	String path = this.properties.getPath();
	String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
	ServletRegistrationBean registration = new ServletRegistrationBean(servlet,
			urlMapping);
	WebServicesProperties.Servlet servletProperties = this.properties.getServlet();
	registration.setLoadOnStartup(servletProperties.getLoadOnStartup());
	for (Map.Entry<String, String> entry : servletProperties.getInit().entrySet()) {
		registration.addInitParameter(entry.getKey(), entry.getValue());
	}
	return registration;
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:17,代碼來源:WebServicesAutoConfiguration.java

示例11: sslDisabled

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
@Test
public void sslDisabled() throws Exception {
	AbstractEmbeddedServletContainerFactory factory = getFactory();
	Ssl ssl = getSsl(null, "password", "classpath:test.jks");
	ssl.setEnabled(false);
	factory.setSsl(ssl);
	this.container = factory.getEmbeddedServletContainer(
			new ServletRegistrationBean(new ExampleServlet(true, false), "/hello"));
	this.container.start();
	SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
			new SSLContextBuilder()
					.loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
	HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
			.build();
	HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
			httpClient);
	this.thrown.expect(SSLException.class);
	getResponse(getLocalUrl("https", "/hello"), requestFactory);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:20,代碼來源:AbstractEmbeddedServletContainerFactoryTests.java

示例12: sslGetScheme

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
@Test
public void sslGetScheme() throws Exception { // gh-2232
	AbstractEmbeddedServletContainerFactory factory = getFactory();
	factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
	this.container = factory.getEmbeddedServletContainer(
			new ServletRegistrationBean(new ExampleServlet(true, false), "/hello"));
	this.container.start();
	SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
			new SSLContextBuilder()
					.loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
	HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
			.build();
	HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
			httpClient);
	assertThat(getResponse(getLocalUrl("https", "/hello"), requestFactory))
			.contains("scheme=https");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:AbstractEmbeddedServletContainerFactoryTests.java

示例13: compressionWithoutContentSizeHeader

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
@Test
public void compressionWithoutContentSizeHeader() throws Exception {
	AbstractEmbeddedServletContainerFactory factory = getFactory();
	Compression compression = new Compression();
	compression.setEnabled(true);
	factory.setCompression(compression);
	this.container = factory.getEmbeddedServletContainer(
			new ServletRegistrationBean(new ExampleServlet(false, true), "/hello"));
	this.container.start();
	TestGzipInputStreamFactory inputStreamFactory = new TestGzipInputStreamFactory();
	Map<String, InputStreamFactory> contentDecoderMap = Collections
			.singletonMap("gzip", (InputStreamFactory) inputStreamFactory);
	getResponse(getLocalUrl("/hello"),
			new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create()
					.setContentDecoderRegistry(contentDecoderMap).build()));
	assertThat(inputStreamFactory.wasCompressionUsed()).isTrue();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:AbstractEmbeddedServletContainerFactoryTests.java

示例14: sessionServletRegistration

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
protected final ServletContextInitializer sessionServletRegistration() {
	ServletRegistrationBean bean = new ServletRegistrationBean(new ExampleServlet() {

		@Override
		public void service(ServletRequest request, ServletResponse response)
				throws ServletException, IOException {
			HttpSession session = ((HttpServletRequest) request).getSession(true);
			long value = System.currentTimeMillis();
			Object existing = session.getAttribute("boot");
			session.setAttribute("boot", value);
			PrintWriter writer = response.getWriter();
			writer.append(String.valueOf(existing) + ":" + value);
		}

	}, "/session");
	bean.setName("session");
	return bean;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:19,代碼來源:AbstractEmbeddedServletContainerFactoryTests.java

示例15: accessLogCanBeEnabled

import org.springframework.boot.web.servlet.ServletRegistrationBean; //導入依賴的package包/類
@Test
public void accessLogCanBeEnabled()
		throws IOException, URISyntaxException, InterruptedException {
	UndertowEmbeddedServletContainerFactory factory = getFactory();
	factory.setAccessLogEnabled(true);
	File accessLogDirectory = this.temporaryFolder.getRoot();
	factory.setAccessLogDirectory(accessLogDirectory);
	assertThat(accessLogDirectory.listFiles()).isEmpty();
	this.container = factory.getEmbeddedServletContainer(
			new ServletRegistrationBean(new ExampleServlet(), "/hello"));
	this.container.start();
	assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
	File accessLog = new File(accessLogDirectory, "access_log.log");
	awaitFile(accessLog);
	assertThat(accessLogDirectory.listFiles()).contains(accessLog);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:UndertowEmbeddedServletContainerFactoryTests.java


注:本文中的org.springframework.boot.web.servlet.ServletRegistrationBean類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。