本文整理汇总了Java中org.springframework.web.util.Log4jConfigListener类的典型用法代码示例。如果您正苦于以下问题:Java Log4jConfigListener类的具体用法?Java Log4jConfigListener怎么用?Java Log4jConfigListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Log4jConfigListener类属于org.springframework.web.util包,在下文中一共展示了Log4jConfigListener类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.springframework.web.util.Log4jConfigListener; //导入依赖的package包/类
public static Server start(JettyProperties properties) throws Throwable {
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(properties.jettyThreadPoolCount);
Server server = new Server(threadPool);
ServerConnector http = new ServerConnector(server,new HttpConnectionFactory());
http.setPort(properties.jettyPort);
server.addConnector(http);
WebAppContext context = new WebAppContext();
// Logging configured per environment:
context.addEventListener(new Log4jConfigListener());
context.setInitParameter("log4jConfigLocation", "file:" + properties.log4jConfigPath);
context.setInitParameter("log4jExposeWebAppRoot", "false");
context.setDescriptor(new ClassPathResource("src/main/webapp/WEB-INF/web.xml").getURI().toString());
if (properties.customWebappContextPath.isPresent()) {
context.setResourceBase(properties.customWebappContextPath.get());
} else {
context.setResourceBase(new ClassPathResource("src/main/webapp").getURI().toString());
}
context.setContextPath("/");
context.setParentLoaderPriority(true);
context.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
context.setInitParameter("spring.profiles.active", properties.springProfile);
server.setHandler(context);
server.start();
return server;
}
示例2: initLog4j
import org.springframework.web.util.Log4jConfigListener; //导入依赖的package包/类
protected void initLog4j(ServletContext servletContext) {
final String log4jConfigLocationParam = "log4jConfigLocation";
final String log4jConfigLocation = servletContext.getInitParameter(log4jConfigLocationParam);
if(Strings.isNullOrEmpty(log4jConfigLocation)) {
servletContext.setInitParameter(log4jConfigLocationParam, getDefaultLog4jConfigLocation());
}
servletContext.setInitParameter("log4jExposeWebAppRoot", "false");
servletContext.addListener(Log4jConfigListener.class);
}
示例3: addListeners
import org.springframework.web.util.Log4jConfigListener; //导入依赖的package包/类
protected void addListeners(final ServletContext ctx) {
ctx.addListener(new ContextLoaderListener(rootContext));
Log4jConfigListener lcl = new Log4jConfigListener();
ctx.addListener(lcl);
}
示例4: onStartup
import org.springframework.web.util.Log4jConfigListener; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// Setup Context to Accept Annotated Classes on Input (including plain Spring {@code @Component}
// Stereotypes in addition to JSR-330 Compliant Classes using {@code javax.inject}
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
//context.setConfigLocation(APP_CONFIG_LOCATION);
context.setConfigLocation(APP_CONFIG_LOCATION);
/*
* Add a Spring Security Filter using the JEE6 Filter Registration Filter Method from {@code FilterRegistration) that allows filters to be registered
* and configured with the specified context
*/
/*
FilterRegistration.Dynamic securityFilter = servletContext.addFilter(ProjectKeyValConsts.SECURITY_FILTER.getKey(), new DelegatingFilterProxy(ProjectKeyValConsts.SECURITY_FILTER.getValue()));
securityFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ProjectConsts.BASE_URL_MAPPING_PATTERN.getValue()); // where the filter will be applied
*/
// Add a Character Encoding Filter that specifies an encoding for mapped requests
FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter());
characterEncodingFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ROOT_CONTEXT); // where the filter will be applied
characterEncodingFilter.setInitParameter("encoding", "UTF-8");
characterEncodingFilter.setInitParameter("forceEncoding", Boolean.TRUE.toString());
characterEncodingFilter.setAsyncSupported(true);
servletContext.addListener(new ContextLoaderListener(context));
servletContext.setInitParameter("defaultHtmlEscape", Boolean.TRUE.toString());
DispatcherServlet servlet = new DispatcherServlet();
// no explicit configuration reference here: everything is configured in the root container for simplicity
servlet.setContextConfigLocation("");
/* TMT From JEE 6 API Docs:
* Registers the given servlet instance with this ServletContext under the given servletName.
* The registered servlet may be further configured via the returned ServletRegistration object.
*/
ServletRegistration.Dynamic appServlet = servletContext.addServlet(APP_SERVLET, servlet);
appServlet.setLoadOnStartup(1);
appServlet.setAsyncSupported(true);
Set<String> mappingConflicts = appServlet.addMapping("/");
if (!mappingConflicts.isEmpty()) {
throw new IllegalStateException(String.format("The servlet named '%s' cannot be mapped to '/' under Tomcat versions <= 7.0.14", APP_SERVLET));
}
// TMT
servletContext.addListener(new Log4jConfigListener());
System.out.println("Application inplemented on Spring Version: " + SpringVersion.getVersion());
}
示例5: registerListener
import org.springframework.web.util.Log4jConfigListener; //导入依赖的package包/类
private void registerListener(ServletContext servletContext) {
servletContext.addListener(new Log4jConfigListener());
servletContext.addListener(new RequestContextListener());
}