簡體   English   中英

我可以將 META-INF 文件夾放入 Spring 命令行應用程序的 src/main/resources 中嗎?

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

我正在研究使用 Spring 實現的批處理應用程序。

在這個應用程序中,我發現了以下結構:

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

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

這批工作正常,但我有一些疑問:這個地方可以認為是放置applicationContext.xml文件的正確位置嗎?

我總是看到META-INF目錄到 web 應用程序(而不是批處理應用程序)到我在這個項目中沒有的以下文件夾中(因為它不是 web 應用程序):

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

這是正確的還是我可以做得更好?

這批工作正常,但我有一些疑問:這個地方可以認為是放置 applicationContext.xml 文件的正確位置嗎?

是的,這很好。 這是一個 Spring Boot 示例,它正是這樣做的

META-INF旨在包含MANIFEST.MF文件和與ServiceLoader類相關的services子目錄,但其他框架(包括 Spring)也使用它。

參考資料:

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

對於 Spring-batch,它應該位於:

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

所以,在你的情況下將是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM