Failed to process import candidates for configuration class

前端 未结 5 1859
北海茫月
北海茫月 2020-12-02 23:55

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

相关标签:
5条回答
  • 2020-12-03 00:03

    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.

    0 讨论(0)
  • 2020-12-03 00:03

    I switched from mvn clean compile assembly:single to mvn clean package and the error went away.

    0 讨论(0)
  • 2020-12-03 00:06

    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
    }
    
    0 讨论(0)
  • 2020-12-03 00:07

    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.

    0 讨论(0)
  • 2020-12-03 00:25

    I solved it as follows:

    1. Delete the spring-boot-maven-plugin
    2. Config spring transformers in shade plugin please refer to spring parent pom
    0 讨论(0)
提交回复
热议问题