简体   繁体   中英

Cannot load spring configuration xml from external jar file

I've tried the solutions written here at stackoverflow, but none of them has resolved my issue, might be different for me.

I have two modules, "email-service" (jar) and "email-service-web" (war) wrapping module. I use maven and the "email-service-web" imports the "email-service" jar file. This works as expected.

My web.xml in "email-service-web" WEB-INF folder looks like this:

<servlet>
    <servlet-name>springServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath*:/META-INF/spring/web-application-config.xml
        </param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>springServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

The web-application-config.xml looks like this:

<import resource="classpath*:applicationContext-email-service-bootstrap.xml"/>
<import resource="classpath*:applicationContext-email-service-environment.xml"/>
<import resource="classpath*:applicationContext-email-service-process.xml"/>
<import resource="classpath*:applicationContext-email-service-integration.xml"/>

<context:component-scan base-package="com.company.emailservice"/>

IntelliJ says it can find the applicationContext-* files, by not showing them in red. I've confirmed that they exist in the email-service.jar file and that the jar file exists in the lib folder of the exploded email-service-web.war file. Also, I've tried various pathing suggestion as classpath*:**/application*.xml etc, nothing happens. I have an HTTP inbound channel adapter in my integration, jetty cannot find this and gives a 404.

The spring part is not starting up, I should get the log spam from it but I don't. If I convert the "email-service" to a war packaged project, and move the webapp structure there, everything works.

What am I doing wrong?

EDIT:

Suggestion that WEB-INF should not be involved, so I've moved files and updated my question above.

Additionally, my structures for the projects are as follows:

[email-service]
`--src
   `--main
      `--src
         |--java (classes)
         `--resources
            |--applicationContext-email-service-bootstrap.xml
            |--applicationContext-email-service-environment.xml
            |--applicationContext-email-service-process.xml
            `--applicationContext-email-service-integration.xml

[email-service-web]
`--src
   `--main
      |--src
      |  `--resources
      |     `--META-INF
      |        `--spring
      |           `--web-application-config.xml
      `--webapp
         `--WEB-INF
            `--web.xml

So, as M. Deinum mentioned, WEB-INF folder is not in the classpath, and this was ultimately my problem.

Took a while to figure out because the HTTP integration endpoint (HTTP inbound channel adapter) did not respond correctly the first few attempts, 3rd and 4th requests did however respond as expected.

Putting web-application-config.xml in resources folder did solve the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM