Implementation of WebApplicationInitializer not loaded from library jar

时间:2018-09-18 19:36:40

标签: java spring java-ee classpath

I have the following project structure:

root
|---- web_1 (war)
|
|---- web_2 (war)
|
|---- common-security (jar)
|
|---- ear_1 (war_1 + common-security)
|
|---- ear_2 (war_2 + common-security)

In this common-security, I have added dependency of org.springframework:spring-web:5.0.9.RELEASE.

This is a sample implementation of WebApplicationInitializer which present in common-security:

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.WebApplicationInitializer;

public class MySecureWebApplicationInitializer implements WebApplicationInitializer {

    private final Logger logger = LogManager.getLogger(getClass());

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        logger.info("m");
    }
}

Each ear contain a war file and the common-security jar. The common-security jar is added in the Class-Path in the META-INF/MANIFEST.MF of the war module. Each of the war file contains web.xml and my servlet version is 3.1.

When I hit the landing page I see:

No Spring WebApplicationInitializer types detected on classpath

But if I duplicate the implementation of WebApplicationInitializer in any war module and remove the dependency of common-security, from that module I see it detects one WebApplicationInitializer and logs the designated message.

I need to have one common module of spring and security which will be used by two different wars.

Any pointer would be great.

0 个答案:

没有答案