简体   繁体   English

无法从外部jar文件加载spring配置xml

[英]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. 我已经尝试过在stackoverflow上编写的解决方案,但是没有一个解决了我的问题,可能对我来说不一样。

I have two modules, "email-service" (jar) and "email-service-web" (war) wrapping module. 我有两个模块,“电子邮件服务”(jar)和“电子邮件服务Web”(war)包装模块。 I use maven and the "email-service-web" imports the "email-service" jar file. 我使用maven,“ email-service-web”导入“ email-service” jar文件。 This works as expected. 这按预期工作。

My web.xml in "email-service-web" WEB-INF folder looks like this: 我在“ email-service-web” WEB-INF文件夹中的web.xml如下所示:

<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: web-application-config.xml如下所示:

<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. IntelliJ表示,可以通过不将其显示为红色来找到applicationContext- *文件。 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. 我已经确认它们存在于email-service.jar文件中,并且jar文件存在于展开的email-service-web.war文件的lib文件夹中。 Also, I've tried various pathing suggestion as classpath*:**/application*.xml etc, nothing happens. 另外,我尝试了各种路径建议,例如classpath *:** / application * .xml等,什么也没有发生。 I have an HTTP inbound channel adapter in my integration, jetty cannot find this and gives a 404. 我在集成中有一个HTTP入站通道适配器,jetty找不到它,并给出了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. 如果我将“电子邮件服务”转换为战争打包的项目,然后将webapp结构移到那里,一切正常。

What am I doing wrong? 我究竟做错了什么?

EDIT: 编辑:

Suggestion that WEB-INF should not be involved, so I've moved files and updated my question above. 建议不要涉及WEB-INF,因此我已经移动文件并更新了我的问题。

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. 因此,正如M. Deinum所述, WEB-INF文件夹不在类路径中,这最终是我的问题。

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. 花了一段时间找出原因,因为在最初的几次尝试中,HTTP集成端点(HTTP入站通道适配器)未正确响应,但是第3和第4个请求却按预期进行了响应。

Putting web-application-config.xml in resources folder did solve the problem. web-application-config.xml放在resources文件夹中确实解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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