2016-03-22 8 views
0

私は、Spring 4 Webアプリケーションの100%コード構成アプローチを使用してアプリケーションを構築しています。以下は私のWeb configクラスです。Spring 4 WebApplicationInitializer log4j2複数の初期化の問題

public class WebAppInitializer extends Log4jServletContainerInitializer implements WebApplicationInitializer { 


    public void onStartup(ServletContext container) throws ServletException { 
     super.onStartup(null, container); 

     // Create the 'root' Spring application context 
     AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); 
     rootContext.register(MyAppContext.class); 

     // Manage the lifecycle of the root application context 
     container.addListener(new ContextLoaderListener(rootContext)); 

     // Create the dispatcher servlet's Spring application context 
     AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext(); 
     webContext.register(MyServletContext.class); 

     // Register and map the dispatcher servlet 
     ServletRegistration.Dynamic dynamic = container.addServlet("dispatcher", new DispatcherServlet(webContext)); 
     dynamic.setLoadOnStartup(1); 
     dynamic.addMapping("/api/*"); 
    } 
} 

問題 -

。私の豆は2回初期化されています

b。私のリソースに(mavenを使って)logj2.xmlを追加すると、いつでも私のBeanの作成は失敗します。

私はこれに新しいです、親切に私を助けてください。

Log4Jの - 2.5、Tomcatの - 8.0.32

ありがとう!

答えて

0

私はそれを修正することができました。 WebApplInitializerの問題ではありませんでしたが、Spring Java Configurationsファイルがありました。私はApplicationContextとServletContextのために別々のconfigsを維持していました。 ApplicationContextでは、

@ComponentScan(value = "com.application.module", 
excludeFilters = {@ComponentScan.Filter(value = {Configuration.class})}) 

を使っています。

は、サーブレットコンテキストでは、私が使用 -

@ComponentScan(basePackageClasses = AppContext.class) 
関連する問題