java 我可以将 META-INF 文件夹放入 Spring 命令行应用程序的 src/main/resources 中吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38200523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 03:12:57  来源:igfitidea点击:

Can I have the META-INF folder into src/main/resources of a Spring command line application?

javaspringapplicationcontextmeta-inf

提问by AndreaNobili

I am working on a batch aplication implemented using Spring.

我正在研究使用 Spring 实现的批处理应用程序。

In this application I found the following structure:

在这个应用程序中,我发现了以下结构:

BATCH PROJECT
      |
      |
      |------> src/main/java (containing the packages)
      |
      |------> src/main/resources
                      |
                      |----------> META-INF
                                      |
                                      |--------> applicationContext.xml (Spring configuration file)

So, as you can see in the previous schema, into the src/main/resourcesI found the META-INFfolder that contain the applicationContext.xmlfile that contains the Spring configuration (the beans definition).

因此,正如您在前面的模式中看到的,在src/main/resources 中,我找到了META-INF文件夹,其中包含applicationContext.xml文件,该文件包含 Spring 配置(bean 定义)。

This batch works fine but I have some doubt: can this place considered the correct place where to put the applicationContext.xmlfile ?

这批工作正常,但我有一些疑问:这个地方可以认为是放置applicationContext.xml文件的正确位置吗?

I always see the META-INFdirectory into web application (and not batch application as this) into the following folder that I don't have in this project (because it is not a web application):

我总是看到META-INF目录到 web 应用程序(而不是批处理应用程序)到我在这个项目中没有的以下文件夹中(因为它不是 web 应用程序):

webapp
|
|_src
|
|_WebContent
  |
  |__WEB-INF
  |
  |__META-INF

Is it correct or can I do better?

这是正确的还是我可以做得更好?

回答by ck1

This batch works fine but I have some doubt: can this place considered the correct place where to put the applicationContext.xml file ?

这批工作正常,但我有一些疑问:这个地方可以认为是放置 applicationContext.xml 文件的正确位置吗?

Yes, this is fine. Here is a Spring Boot example that is doing precisely this.

是的,这很好。 这是一个 Spring Boot 示例,它正是这样做的

META-INFis intended to contain the MANIFEST.MFfile and the servicessubdirectory related to the ServiceLoaderclass, but other frameworks, including Spring, use it as well.

META-INF旨在包含与类相关的MANIFEST.MF文件和services子目录ServiceLoader,但其他框架,包括 Spring,也使用它。

References:

参考:

http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#The_META-INF_directory

http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#The_META-INF_directory

http://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html

http://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html

回答by fidudidu

For Spring-batch it should be located under:

对于 Spring-batch,它应该位于:

META-INF/spring/batch/jobs/*.xml

META-INF/spring/batch/jobs/*.xml

So, in your case would be:

所以,在你的情况下将是:

WebContent/META-INF/spring/batch/jobs/applicationContext.xml

WebContent/META-INF/spring/batch/jobs/applicationContext.xml