0
我有一个Spring PrimeFaces JSF应用程序被配置为通过实现WebApplicationInitializer
而不是web.xml
(尽管我还有一个空的web.xml
)的类加载应用程序。问题是在应用程序启动时,基本上在整个应用程序中,方法被调用两次!我发现的最佳解释是可能会对其中一个听众进行双重加载。我没有看到我正在那样做。下面是我的WebApplicationInitializer
类。我不知道还有什么可以解决我的问题。即使托管bean方法被调用两次。Spring方法被调用两次
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>
当应用程序启动时,我看到春天输出也被复制!
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。
这似乎是一个记录器问题。 –
什么我可以尝试的指针?或者您需要的更多信息? – raylee
你正在使用什么日志框架? Log4j,logback,其他?发布您的记录器配置。 –