本文整理汇总了Java中org.springframework.boot.context.embedded.ServletContextInitializer类的典型用法代码示例。如果您正苦于以下问题:Java ServletContextInitializer类的具体用法?Java ServletContextInitializer怎么用?Java ServletContextInitializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServletContextInitializer类属于org.springframework.boot.context.embedded包,在下文中一共展示了ServletContextInitializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEmbeddedServletContainer
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
ServletContextInitializer... initializers) {
Tomcat tomcat = new Tomcat();
File baseDir = (this.baseDirectory != null ? this.baseDirectory
: createTempDir("tomcat"));
tomcat.setBaseDir(baseDir.getAbsolutePath());
Connector connector = new Connector(this.protocol);
tomcat.getService().addConnector(connector);
customizeConnector(connector);
tomcat.setConnector(connector);
tomcat.getHost().setAutoDeploy(false);
tomcat.getEngine().setBackgroundProcessorDelay(-1);
for (Connector additionalConnector : this.additionalTomcatConnectors) {
tomcat.getService().addConnector(additionalConnector);
}
prepareContext(tomcat.getHost(), initializers);
return getTomcatEmbeddedServletContainer(tomcat);
}
示例2: servletContextInitializer
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
@Bean
public ServletContextInitializer servletContextInitializer() {
return new ServletContextInitializer() {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
String loggingServerIP = portalConfig.cloggingUrl();
String loggingServerPort = portalConfig.cloggingPort();
String credisServiceUrl = portalConfig.credisServiceUrl();
servletContext.setInitParameter("loggingServerIP",
Strings.isNullOrEmpty(loggingServerIP) ? "" : loggingServerIP);
servletContext.setInitParameter("loggingServerPort",
Strings.isNullOrEmpty(loggingServerPort) ? "" : loggingServerPort);
servletContext.setInitParameter("credisServiceUrl",
Strings.isNullOrEmpty(credisServiceUrl) ? "" : credisServiceUrl);
}
};
}
示例3: getEmbeddedServletContainer
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer... initializers) {
ClassLoader parentClassLoader = resourceLoader != null ? resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader();
Package nettyPackage = Bootstrap.class.getPackage();
String title = nettyPackage.getImplementationTitle();
String version = nettyPackage.getImplementationVersion();
logger.info("Running with " + title + " " + version);
NettyEmbeddedContext context = new NettyEmbeddedContext(getContextPath(), new URLClassLoader(new URL[]{}, parentClassLoader), SERVER_INFO);
if (isRegisterDefaultServlet()) {
logger.warn("This container does not support a default servlet");
}
for (ServletContextInitializer initializer : initializers) {
try {
initializer.onStartup(context);
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
int port = getPort() > 0 ? getPort() : new Random().nextInt(65535 - 1024) + 1024;
InetSocketAddress address = new InetSocketAddress(port);
logger.info("Server initialized with port: " + port);
return new NettyEmbeddedServletContainer(address, context);
}
示例4: configureContext
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
/**
* Configure the Tomcat {@link Context}.
* @param context the Tomcat context
* @param initializers initializers to apply
*/
protected void configureContext(Context context,
ServletContextInitializer[] initializers) {
TomcatStarter starter = new TomcatStarter(initializers);
if (context instanceof TomcatEmbeddedContext) {
// Should be true
((TomcatEmbeddedContext) context).setStarter(starter);
}
context.addServletContainerInitializer(starter, NO_CLASSES);
for (LifecycleListener lifecycleListener : this.contextLifecycleListeners) {
context.addLifecycleListener(lifecycleListener);
}
for (Valve valve : this.contextValves) {
context.getPipeline().addValve(valve);
}
for (ErrorPage errorPage : getErrorPages()) {
new TomcatErrorPage(errorPage).addToContext(context);
}
for (MimeMappings.Mapping mapping : getMimeMappings()) {
context.addMimeMapping(mapping.getExtension(), mapping.getMimeType());
}
configureSession(context);
for (TomcatContextCustomizer customizer : this.tomcatContextCustomizers) {
customizer.customize(context);
}
}
示例5: onStartup
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
@Override
public void onStartup(Set<Class<?>> classes, ServletContext servletContext)
throws ServletException {
try {
for (ServletContextInitializer initializer : this.initializers) {
initializer.onStartup(servletContext);
}
}
catch (Exception ex) {
this.startUpException = ex;
// Prevent Tomcat from logging and re-throwing when we know we can
// deal with it in the main thread, but log for information here.
if (logger.isErrorEnabled()) {
logger.error("Error starting Tomcat context: " + ex.getClass().getName());
}
}
}
示例6: configureWebAppContext
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
/**
* Configure the given Jetty {@link WebAppContext} for use.
* @param context the context to configure
* @param initializers the set of initializers to apply
*/
protected final void configureWebAppContext(WebAppContext context,
ServletContextInitializer... initializers) {
Assert.notNull(context, "Context must not be null");
context.setTempDirectory(getTempDirectory());
if (this.resourceLoader != null) {
context.setClassLoader(this.resourceLoader.getClassLoader());
}
String contextPath = getContextPath();
context.setContextPath(StringUtils.hasLength(contextPath) ? contextPath : "/");
context.setDisplayName(getDisplayName());
configureDocumentRoot(context);
if (isRegisterDefaultServlet()) {
addDefaultServlet(context);
}
if (shouldRegisterJspServlet()) {
addJspServlet(context);
}
ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
Configuration[] configurations = getWebAppContextConfigurations(context,
initializersToUse);
context.setConfigurations(configurations);
configureSession(context);
postProcessWebAppContext(context);
}
示例7: servletContextInitializer
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
/**
* public void onStartup(ServletContext servletContext) throws ServletException {
* LightAdmin.configure(servletContext)
* .basePackage("org.lightadmin.boot.administration")
* .baseUrl("/admin")
* .security(false)
* .backToSiteUrl("http://lightadmin.org");
* super.onStartup(servletContext);
* }
*/
/* Used for running in "embedded" mode */
@Bean
public ServletContextInitializer servletContextInitializer() {
return new ServletContextInitializer() {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
LightAdmin.configure(servletContext)
//.basePackage("org.lightadmin.boot.administration")
.baseUrl("/lightadmin")
.security(false)
.backToSiteUrl("http://lightadmin.org");
new LightAdminWebApplicationInitializer().onStartup(servletContext);
}
};
}
示例8: getEmbeddedServletContainer
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer... initializers) {
ClassLoader parentClassLoader = resourceLoader != null ? resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader();
Package nettyPackage = Bootstrap.class.getPackage();
String title = nettyPackage.getImplementationTitle();
String version = nettyPackage.getImplementationVersion();
logger.info("Running with " + title + " " + version);
NettyEmbeddedContext context = new NettyEmbeddedContext(getContextPath(), new URLClassLoader(new URL[]{}, parentClassLoader), SERVER_INFO);
if (isRegisterDefaultServlet()) {
logger.warn("This container does not support a default servlet");
}
if (isRegisterJspServlet()) {
logger.warn("This container does not support a JSP servlet");
}
for (ServletContextInitializer initializer : initializers) {
try {
initializer.onStartup(context);
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
int port = getPort() > 0 ? getPort() : new Random().nextInt(65535 - 1024) + 1024;
InetSocketAddress address = new InetSocketAddress(port);
logger.info("Server initialized with port: " + port);
return new NettyEmbeddedServletContainer(address, context);
}
开发者ID:DanielThomas,项目名称:spring-boot-starter-netty,代码行数:27,代码来源:NettyEmbeddedServletContainerFactory.java
示例9: servletContextInitializer
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
/**
* public void onStartup(ServletContext servletContext) throws ServletException {
* LightAdmin.configure(servletContext)
* .basePackage("org.lightadmin.boot.administration")
* .baseUrl("/admin")
* .security(false)
* .backToSiteUrl("http://lightadmin.org");
* super.onStartup(servletContext);
* }
*/
/* Used for running in "embedded" mode */
@Bean
public ServletContextInitializer servletContextInitializer() {
return new ServletContextInitializer() {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
LightAdmin.configure(servletContext)
.basePackage("org.lightadmin.boot.administration")
.baseUrl("/admin")
.security(true)
.backToSiteUrl("http://lightadmin.org");
new LightAdminWebApplicationInitializer().onStartup(servletContext);
}
};
}
示例10: servletContextInitializer
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
@Bean
public ServletContextInitializer servletContextInitializer() {
return servletContext -> {
servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", Boolean.TRUE.toString());
servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", "true");
servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development");
servletContext.addListener(com.sun.faces.config.ConfigureListener.class);
servletContext.setInitParameter("BootsFaces_THEME", "default");
};
}
示例11: servletContextInitializer
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
@Bean
public ServletContextInitializer servletContextInitializer() {
return servletContext -> {
servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", Boolean.TRUE.toString());
};
}
示例12: servletContextInitializer
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Bean
public ServletContextInitializer servletContextInitializer() {
return new ServletContextInitializer() {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
sessionCookieConfig.setHttpOnly(true);
}
};
}
示例13: prepareContext
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
protected void prepareContext(Host host, ServletContextInitializer[] initializers) {
File docBase = getValidDocumentRoot();
docBase = (docBase != null ? docBase : createTempDir("tomcat-docbase"));
TomcatEmbeddedContext context = new TomcatEmbeddedContext();
context.setName(getContextPath());
context.setDisplayName(getDisplayName());
context.setPath(getContextPath());
context.setDocBase(docBase.getAbsolutePath());
context.addLifecycleListener(new FixContextListener());
context.setParentClassLoader(
this.resourceLoader != null ? this.resourceLoader.getClassLoader()
: ClassUtils.getDefaultClassLoader());
SkipPatternJarScanner.apply(context, this.tldSkip);
WebappLoader loader = new WebappLoader(context.getParentClassLoader());
loader.setLoaderClass(TomcatEmbeddedWebappClassLoader.class.getName());
loader.setDelegate(true);
context.setLoader(loader);
if (isRegisterDefaultServlet()) {
addDefaultServlet(context);
}
if (shouldRegisterJspServlet()) {
addJspServlet(context);
addJasperInitializer(context);
context.addLifecycleListener(new StoreMergedWebXmlListener());
}
ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
configureContext(context, initializersToUse);
host.addChild(context);
postProcessContext(context);
}
示例14: getEmbeddedServletContainer
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
ServletContextInitializer... initializers) {
DeploymentManager manager = createDeploymentManager(initializers);
int port = getPort();
Builder builder = createBuilder(port);
return new UndertowEmbeddedServletContainer(builder, manager, getContextPath(),
port, this.useForwardHeaders, port >= 0, getCompression());
}
示例15: createDeploymentManager
import org.springframework.boot.context.embedded.ServletContextInitializer; //导入依赖的package包/类
private DeploymentManager createDeploymentManager(
ServletContextInitializer... initializers) {
DeploymentInfo deployment = Servlets.deployment();
registerServletContainerInitializerToDriveServletContextInitializers(deployment,
initializers);
deployment.setClassLoader(getServletClassLoader());
deployment.setContextPath(getContextPath());
deployment.setDisplayName(getDisplayName());
deployment.setDeploymentName("spring-boot");
if (isRegisterDefaultServlet()) {
deployment.addServlet(Servlets.servlet("default", DefaultServlet.class));
}
configureErrorPages(deployment);
deployment.setServletStackTraces(ServletStackTraces.NONE);
deployment.setResourceManager(getDocumentRootResourceManager());
configureMimeMappings(deployment);
for (UndertowDeploymentInfoCustomizer customizer : this.deploymentInfoCustomizers) {
customizer.customize(deployment);
}
if (isAccessLogEnabled()) {
configureAccessLog(deployment);
}
if (isPersistSession()) {
File folder = getValidSessionStoreDir();
deployment.setSessionPersistenceManager(new FileSessionPersistence(folder));
}
DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment);
manager.deploy();
SessionManager sessionManager = manager.getDeployment().getSessionManager();
int sessionTimeout = (getSessionTimeout() > 0 ? getSessionTimeout() : -1);
sessionManager.setDefaultSessionTimeout(sessionTimeout);
return manager;
}