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

2

8

I am working on a batch aplication implemented using 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/resources I found the META-INF folder that contain the applicationContext.xml file that contains the Spring configuration (the beans definition).

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

I always see the META-INF directory 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):

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

Is it correct or can I do better?

Arcane answered 5/7, 2016 at 10:0 Comment(0)
A
2

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

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

META-INF is intended to contain the MANIFEST.MF file and the services subdirectory related to the ServiceLoader class, but other frameworks, including Spring, use it as well.

References:

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

Ainsley answered 6/7, 2016 at 1:19 Comment(1)
Unfortunately the github link is dead. Do you have a similar example?Frenzied
M
0

For Spring-batch it should be located under:

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

So, in your case would be:

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

Maupassant answered 22/3, 2020 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.