2017-08-07 93 views
0

因此,当我尝试用mvn spring-boot运行我的项目时:运行时出现此构建失败。Spring + java - InvocationTargetException

enter image description here

通过谷歌搜索我想我的问题在于我的pom.xml文件和我的春天版本。但是我无法弄清楚我的确切问题在哪里。这是我的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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.mycompany</groupId> 
    <artifactId>mavenproject1</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>war</packaging> 

    <name>mavenproject1</name> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.6.RELEASE</version> 
    </parent> 

<!-- <properties> 
     <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties>--> 

    <dependencies> 
     <dependency> 
      <groupId>javax</groupId> 
      <artifactId>javaee-web-api</artifactId> 
      <version>6.0</version> 
      <scope>provided</scope> 
     </dependency> 
     <!--Spring--> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>3.2.2.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context</artifactId> 
      <version>3.2.2.RELEASE</version> 
     </dependency> 

     <!--MONGO--> 
     <dependency> 
      <groupId>org.mongodb</groupId> 
      <artifactId>mongo-java-driver</artifactId> 
      <version>2.11.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.data</groupId> 
      <artifactId>spring-data-mongodb</artifactId> 
      <version>1.2.0.RELEASE</version> 
     </dependency> 

     <dependency> 
      <groupId>cglib</groupId> 
      <artifactId>cglib</artifactId> 
      <version>2.2.2</version> 
     </dependency> 


     <dependency> 
      <groupId>org.elasticsearch</groupId> 
      <artifactId>elasticsearch</artifactId> 
      <version>2.4.0</version> 
     </dependency> 


    </dependencies> 

    <build> 
     <plugins>   
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.0</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-eclipse-plugin</artifactId> 
       <version>2.9</version> 
       <configuration> 
        <downloadSources>true</downloadSources> 
        <downloadJavadocs>true</downloadJavadocs> 
       </configuration> 
      </plugin> 
      <!--skal dette bruges?--> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.1.1</version> 
       <configuration> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.1</version> 
       <executions> 
        <execution> 
         <phase>validate</phase> 
         <goals> 
          <goal>copy</goal> 
         </goals> 
         <configuration> 
          <outputDirectory>${endorsed.dir}</outputDirectory> 
          <silent>true</silent> 
          <artifactItems> 
           <artifactItem> 
            <groupId>javax</groupId> 
            <artifactId>javaee-endorsed-api</artifactId> 
            <version>6.0</version> 
            <type>jar</type> 
           </artifactItem> 
          </artifactItems> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

我想建立是连接到MongoDB的,具有REST API弹簧启动应用程序。哦,并使用elasticsearch。

希望有人能看到我要去哪里错了?提前致谢!

**编辑:错误,错误日志:

enter image description here

**更新日志:

enter image description here

+1

最有可能你有一个Java版本不匹配。在控制台上检查Java。 – 11thdimension

+0

我的java版本是1.8.0_121。我怎么知道它是不是一个错误的版本?哪个是正确的? –

+0

没有正确的,有不相容的。尝试在你的pom.xml(maven-compiler-plugin)中更改为1.8。 – Oleg

回答

1

无需手动定义依赖于每个组件。

只需定义mongo和弹性搜索启动器依赖项,并且spring启动将提取组件所需的所有必需兼容依赖项。

的东西替换你的依赖部分像

<dependencies> 
     <dependency> 
      <groupId>javax</groupId> 
      <artifactId>javaee-web-api</artifactId> 
      <version>6.0</version> 
      <scope>provided</scope> 
     </dependency> 

     <!--Spring--> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 

     <!--Mongo--> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-mongodb</artifactId> 
     </dependency> 

     <!--Elasticsearch--> 
     <dependency>       
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-elasticsearch</artifactId> 
    </dependency> 

</dependencies> 
相关问题