We Are Going To Discuss About SpringBoot – making jar files – No auto configuration classes found in META-INF/spring.factories. So lets Start this Java Article.
SpringBoot – making jar files – No auto configuration classes found in META-INF/spring.factories
- SpringBoot – making jar files – No auto configuration classes found in META-INF/spring.factories
At first, I was generating the fat jar with the
maven-assembly-plugin
, which created a file calledmavenproject1-0.0.1-SNAPSHOT-jar-with-dependencies.jar
. This file gave the same problem as you mentioned when I tried running it. - SpringBoot – making jar files – No auto configuration classes found in META-INF/spring.factories
At first, I was generating the fat jar with the
maven-assembly-plugin
, which created a file calledmavenproject1-0.0.1-SNAPSHOT-jar-with-dependencies.jar
. This file gave the same problem as you mentioned when I tried running it.
Solution 1
I had the same problem and just solved it.
At first, I was generating the fat jar with the maven-assembly-plugin
, which created a file called mavenproject1-0.0.1-SNAPSHOT-jar-with-dependencies.jar
. This file gave the same problem as you mentioned when I tried running it.
I think that because it’s a Spring Boot application, you need to use their plug-in. I changed my packaging to the spring-boot-maven-plugin
and it generates two files: mavenproject1-0.0.1-SNAPSHOT.jar
and mavenproject1-0.0.1-SNAPSHOT.jar.original
. Just try java -jar target/mavenproject1-0.0.1-SNAPSHOT.jar
, and it will hopefully work. 🙂
For reference, here is my pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>mavenproject1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.company.common</groupId>
<artifactId>common-files</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>${start-class}</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.company.mavenproject1.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original Author Benoit Larochelle Of This Content
Solution 2
This is the solution :
-
add only plugin in POM.xml
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> <mainClass>${start-class}</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins>
-
One property in pom.xml
<properties> <start-class>com.xxx.yyy.MainClass</start-class> </properties>
-
Run command
mvn clean package spring-boot:repackage
-
Now run your jar (it includes all dependencies now) created inside target folder
java -jar my-service-0.0.1-SNAPSHOT.jar
Original Author Sagar Joon Of This Content
Solution 3
Alternatively, if you cannot use the spring boot plugin for whatever reason, you can include the following file in your application. It should be called src/main/resources/META-INF/spring.factories
:
This will work for spring boot 1.x and is helpful if you want to use spring managed beans in a REPL.
Original Author cscan Of This Content
Solution 4
This configuration works for me. I execute my JAR as a service but the line is:
javaw -jar MY_JAR.jar
POM:
<properties>
<!-- Spring boot main class -->
<start-class>com.PATH_TO_MAIN.Main</start-class>
</properties>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
With Spring Boot, it is no longer necessary to use the assembly-plugin. Do not forget to call the package goal.
Here is the documentation example.
Original Author crm86 Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.