I\'ve a spring boot project that I can run successfully from within IntelliJ, but when I package an executable jar I can no longer run it. Here is the stack trace of the exc
I've also gotten the
Failed to process import candidates for configuration class [...]; nested exception is java.lang.IllegalStateException: Unable to read meta-data for class ...
error due to a typo in my spring.factories
file. In this case the root exception was
class path resource [...] cannot be opened because it does not exist.
This is an important spot to check since it can't be validated at compile time.
I switched from
mvn clean compile assembly:single
to
mvn clean package
and the error went away.
I think that you have forgotten to use Annotation in your AppConfig.
Add following three annotations to your AppConfig
class:
@Configuration
@EnableWebMvc
@ComponentScan("Scan_Package_Name")
public class AppConfig {
... some beans
}
I just figure it out, I should have been using Spring Boot maven plugin instead. Now the build section of my pom.xml
looks like:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>dz.lab.jpmtask.App</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<!--<version>0.7.8-SNAPSHOT</version>-->
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I build the project with mvn clean package
and then java -jar target/myproject.jar
and it works like a charm.
I solved it as follows:
spring-boot-maven-plugin