Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 667
AndreaNobili Avatar asked Jul 05 '16 10:07

AndreaNobili


People also ask

Where should META-INF folder be?

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).

What is META-INF folder in Spring?

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.

How do I create a META-INF folder in Spring boot?

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.

What is META-INF Services folder?

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.


1 Answers

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

like image 190
ck1 Avatar answered Oct 25 '22 16:10

ck1