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?
Basically it has to be in your classpath(under /META-INF/ ). You can manually enable it in eclipse by configuring properties. If your project is maven based, then it should be automatically picked from /src/main/resources/META-INF/ folder (provided entities are under the same hood).
The META-INF folder is the home for the MANIFEST. MF file. This file contains meta data about the contents of the JAR. For example, there is an entry called Main-Class that specifies the name of the Java class with the static main() for executable JAR files.
Click 'Add Folder', click 'Create New Folder', type 'src/main/resources/META-INF', click 'Finish', click 'OK', Click 'Apply and Close', In the source folder '~/src/main/java', create a new Package 'hello' and a new Class file 'Application.
A service provider is identified by placing a provider-configuration file in the resource directory META-INF/services. The file's name is the fully-qualified binary name of the service's type. The file contains a list of fully-qualified binary names of concrete provider classes, one per line.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With