无法处理配置类的导入候选项

时间:2016-09-07 16:21:56

标签: java spring maven spring-boot spring-data-jpa

我有一个Spring Boot项目,我可以在IntelliJ中成功运行,但是当我打包一个可执行jar时,我再也无法运行它了。这是异常的堆栈跟踪:

@Configuration
@EnableAutoConfiguration
public class AppConfig {
  ... some beans
}

我的配置类似于:

META-INF/spring.factories

我已按照43.2 Locating auto-configuration candidates中的说明在项目资源文件夹下添加了org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ el.dorado.AppConfig ,如下所示但是这并没有解决问题:

pom.xml

这是项目<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>el.dorado</groupId> <artifactId>ElDorado</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>ElDorado</name> <url>http://maven.apache.org</url> <properties> <junit.version>4.12</junit.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>el.dorado.App</mainClass> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <!-- this is used for inheritance merges --> <phase>package</phase> <!-- bind to the packaging phase --> <goals> <goal>single</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> </project>

typescript

5 个答案:

答案 0 :(得分:9)

我只是弄明白,我本应该使用Spring Boot maven plugin代替。现在我的pom.xml的构建部分看起来像:

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

我使用mvn clean package然后java -jar target/myproject.jar构建项目,它就像一个魅力。

答案 1 :(得分:1)

我认为你忘了在AppConfig中使用Annotation。

添加三个注释

@Configuration
@EnableWebMvc
@ComponentScan("Scan_Package_Name") 
public class AppConfig {
  ... some beans
}

答案 2 :(得分:0)

我解决了它如下:

  1. 删除 弹簧引导行家-插件
  2. 在shade插件中配置spring变换器 请参阅spring parent pom

答案 3 :(得分:0)

我也得到了

  

无法处理配置类[...]的导入候选项;嵌套异常是java.lang.IllegalStateException:无法读取类的元数据...

由于 // Get All information for LeafPlan $scope.LoadLeaf = function (Id_Leaf) { RESTSummoner.DoGet(PATH_LEAF, "/" + Id_Leaf).succes(function (data) { $scope.Leaf = data; console.log(data); }).error(function () { }); } module.directive('svgPlan', ['$compile', 'RESTSummoner', function ($compile, RESTSummoner) { return { restrict: "A", replace: true, controller: function ($scope) { $scope.PATH_LEAF = 'SV_MAP_LEAF'; alert($scope.PATH_LEAF); }, templateUrl:'', link: function (scope, element, attrs) { scope.PATH_LEAF = 'SV_MAP_LEAF'; alert("coucou"); RESTSummoner.DoGET(1).then(function (res) { alert("coucou"); element.replaceWith(res.data) console.log(res.data); console.log(res.data); }); } } }]) 文件中的拼写错误导致

错误。在这种情况下,根异常是

  

类路径资源[...]无法打开,因为它不存在。

这是一个需要检查的重要位置,因为它无法在编译时进行验证。

答案 4 :(得分:0)

我换了 mvn clean compile assembly:singlemvn clean package 并且错误消失了。