我有一个Spring,PrimeFaces JSF应用程序,它被配置为通过实现WebApplicationInitializer
而不是web.xml
的类来加载应用程序(尽管我仍然只有web.xml
)。问题在于应用程序启动,基本上在整个应用程序中,方法被调用两次!我发现的最佳解释是可能是其中一个听众的双重加载。我不认为我这样做。附件是我下面的WebApplicationInitializer
课程。我不知道还有什么可以解决我的问题。甚至托管bean方法也被调用两次。
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
final CharacterEncodingFilter cf = new CharacterEncodingFilter();
cf.setEncoding("UTF-8");
cf.setForceEncoding(true);
servletContext.addListener(new RequestContextListener());
servletContext
.addFilter(
"ShiroFilter",
org.apache.shiro.web.servlet.IniShiroFilter.class)
.addMappingForUrlPatterns(null, false, "/*");
final WebApplicationContext context = getContext();
servletContext.addListener(new ContextLoaderListener(context));
final ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("*.do");
}
private AnnotationConfigWebApplicationContext getContext() {
final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(AppConfig.class);
return context;
}
}
我的web.xml
具有面部的标准定义和以下映射:
.....
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
.....
<!-- JSF Mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
当应用程序启动时,我看到Spring的输出也是重复的!
2013-12-12T11:29:56.430-0500|INFO: [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] - Refreshing Root WebApplicationContext: startup date [Thu Dec 12 11:29:56 EST 2013]; root of context hierarchy
2013-12-12T11:29:56.430-0500|INFO: [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] - Refreshing Root WebApplicationContext: startup date [Thu Dec 12 11:29:56 EST 2013]; root of context hierarchy
2013-12-12T11:29:56.978-0500|INFO: [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
2013-12-12T11:29:56.978-0500|INFO: [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
如何停止重复通话?感谢。
修改 我正在使用Log4j。这是我的配置:
log4j.rootLogger=info, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[%c] %x - %m%n
log4j.logger.org.hibernate=info, A1
log4j.logger.com.telus=info, A1
log4j.logger.org.springframework=info, A1
使用Spring 3.1.4.RELEASE。 PrimeFaces 4.0。 JSF 2.1.7。部署在Glassfish 3. Java 1.6.32。
答案 0 :(得分:0)
尝试将以下内容添加到log4j.properties
log4j.additivity.org.hibernate=false
log4j.additivity.com.telus=false
log4j.additivity.org.springframework=false
这应该确保父根记录器不会复制日志消息。