无法使用java -jar运行spring-boot应用程序(不是托管类型)

时间:2018-04-05 09:59:43

标签: java spring spring-boot jar

我无法使用java -jar ...命令运行spring-boot应用程序。

我可以使用命令mvnw spring-boot:run运行它。以下是此命令的输出:

  

命令: mvnw spring-boot:run

C:\Workspace\workspaceIntranet\intranet\intranet-business-rest>mvnw spring-boot:run
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.intranet.si:intranet-business-rest:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-beans:jar -> duplicate declaration of version ${spring.version} @ com.intranet.si:intranet:0.0.1-SNAPSHOT, C:\Workspace\workspaceIntranet\intranet\pom.xml, line 218, column 16
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building intranet-business-rest 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.5.8.RELEASE:run (default-cli) > test-compile @ intranet-business-rest >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ intranet-business-rest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ intranet-business-rest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ intranet-business-rest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Workspace\workspaceIntranet\intranet\intranet-business-rest\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ intranet-business-rest ---
[INFO] No sources to compile
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.5.8.RELEASE:run (default-cli) < test-compile @ intranet-business-rest <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.8.RELEASE:run (default-cli) @ intranet-business-rest ---
  ___   _   _   _____   ____       _      _   _   _____   _____
 |_ _| | \ | | |_   _| |  _ \     / \    | \ | | | ____| |_   _|
  | |  |  \| |   | |   | |_) |   / _ \   |  \| | |  _|     | |
  | |  | |\  |   | |   |  _ <   / ___ \  | |\  | | |___    | |
 |___| |_| \_|   |_|   |_| \_\ /_/   \_\ |_| \_| |_____|   |_|
 :: Spring Boot (v1.5.8.RELEASE) - INTRANET REST Resource Application ::

2018-04-05 10:47:38.075  INFO 4876 --- [           main] com.intranet.si.config.MainApplication   : Starting MainApplication on SI-HELOUFIR-DL with PID 4876 (C:\Workspace\workspaceIntranet\intranet\intranet-business-rest\target\classes started by heloufir in C:\Workspace\workspaceIntranet\intranet\intranet-business-rest)
...
...
...
...
2018-04-05 10:47:54.806  INFO 4876 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-04-05 10:47:54.812  INFO 4876 --- [           main] com.intranet.si.config.MainApplication   : Started MainApplication in 16.977 seconds (JVM running for 19.907)

但是当我使用命令java -jar清理+安装并运行应用程序时,我出现以下错误:

  

命令: mvnw clean&amp;&amp; mvnw install&amp;&amp; cd target&amp;&amp; java -jar intranet-business-rest-0.0.1-SNAPSHOT.jar

C:\Workspace\workspaceIntranet\intranet\intranet-business-rest>mvnw clean && mvnw install && cd target && java -jar intranet-business-rest-0.0.1-SNAPSHOT.jar
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.intranet.si:intranet-business-rest:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-beans:jar -> duplicate declaration of version ${spring.version} @ com.intranet.si:intranet:0.0.1-SNAPSHOT, C:\Workspace\workspaceIntranet\intranet\pom.xml, line 218, column 16
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building intranet-business-rest 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ intranet-business-rest ---
[INFO] Deleting C:\Workspace\workspaceIntranet\intranet\intranet-business-rest\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.480 s
[INFO] Finished at: 2018-04-05T10:53:58+01:00
[INFO] Final Memory: 12M/368M
[INFO] ------------------------------------------------------------------------
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.intranet.si:intranet-business-rest:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-beans:jar -> duplicate declaration of version ${spring.version} @ com.intranet.si:intranet:0.0.1-SNAPSHOT, C:\Workspace\workspaceIntranet\intranet\pom.xml, line 218, column 16
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building intranet-business-rest 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ intranet-business-rest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ intranet-business-rest ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 50 source files to C:\Workspace\workspaceIntranet\intranet\intranet-business-rest\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ intranet-business-rest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Workspace\workspaceIntranet\intranet\intranet-business-rest\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ intranet-business-rest ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ intranet-business-rest ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ intranet-business-rest ---
[INFO] Building jar: C:\Workspace\workspaceIntranet\intranet\intranet-business-rest\target\intranet-business-rest-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.8.RELEASE:repackage (default) @ intranet-business-rest ---
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ intranet-business-rest ---
[INFO] Installing C:\Workspace\workspaceIntranet\intranet\intranet-business-rest\target\intranet-business-rest-0.0.1-SNAPSHOT.jar to C:\Users\heloufir\.m2\repository\com\intranet\si\intranet-business-rest\0.0.1-SNAPSHOT\intranet-business-rest-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Workspace\workspaceIntranet\intranet\intranet-business-rest\pom.xml to C:\Users\heloufir\.m2\repository\com\intranet\si\intranet-business-rest\0.0.1-SNAPSHOT\intranet-business-rest-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.800 s
[INFO] Finished at: 2018-04-05T10:54:03+01:00
[INFO] Final Memory: 41M/375M
[INFO] ------------------------------------------------------------------------
  ___   _   _   _____   ____       _      _   _   _____   _____
 |_ _| | \ | | |_   _| |  _ \     / \    | \ | | | ____| |_   _|
  | |  |  \| |   | |   | |_) |   / _ \   |  \| | |  _|     | |
  | |  | |\  |   | |   |  _ <   / ___ \  | |\  | | |___    | |
 |___| |_| \_|   |_|   |_| \_\ /_/   \_\ |_| \_| |_____|   |_|
 :: Spring Boot (v1.5.8.RELEASE) - INTRANET REST Resource Application ::

2018-04-05 10:54:05.336  INFO 8784 --- [           main] com.intranet.si.config.MainApplication   : Starting MainApplication v0.0.1-SNAPSHOT on
...
...
...
...
2018-04-05 10:54:13.757  WARN 8784 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeResource': Unsatisfied dependency expressed through field 'hrServicesSilo'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hrServicesSilo': Unsatisfied dependency expressed through field 'employeeService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeService': Unsatisfied dependency expressed through field 'employeeRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.intranet.si.model.hr.Employee
2018-04-05 10:54:13.773  INFO 8784 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'com.intranet.si.jpa'
2018-04-05 10:54:13.777  INFO 8784 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-04-05 10:54:13.793  INFO 8784 --- [           main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-04-05 10:54:13.809 ERROR 8784 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeResource': Unsatisfied dependency expressed through field 'hrServicesSilo'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hrServicesSilo': Unsatisfied dependency expressed through field 'employeeService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeService': Unsatisfied dependency expressed through field 'employeeRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.intranet.si.model.hr.Employee
        ...
        ...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hrServicesSilo': Unsatisfied dependency expressed through field 'employeeService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeService': Unsatisfied dependency expressed through field 'employeeRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.intranet.si.model.hr.Employee
        ...
        ...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeService': Unsatisfied dependency expressed through field 'employeeRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.intranet.si.model.hr.Employee
        ...
        ...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.intranet.si.model.hr.Employee
        ...
        ...
Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.intranet.si.model.hr.Employee
        ...
        ...

以下是项目架构的快速浏览

enter image description here

以下是Main spring-boot应用程序类

enter image description here

以下是 intranet-business-rest 图层的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>
    <name>intranet-business-rest</name>
    <artifactId>intranet-business-rest</artifactId>
    <packaging>jar</packaging>
    <parent>
        <groupId>com.intranet.si</groupId>
        <artifactId>intranet</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>com.intranet.si</groupId>
            <artifactId>intranet-business-orchestration</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-jwt</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-dbcp</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <addResources>true</addResources>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <start-class>com.intranet.si.config.MainApplication</start-class>
    </properties>
</project>

我已经尝试了on this question所描述的内容,但仍然遇到了相同的错误

修改

以下是员工模型:

package com.intranet.si.model.hr;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.intranet.si.model.global.Historized;
import com.intranet.si.model.referentiel.EmployeeStatus;

@Entity
@Table(name = "hr_employee_tb")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Employee extends Historized implements Serializable {

    private static final long serialVersionUID = -4800231858568799896L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;

    @Column(name = "MATRICULE", unique = true, length = 5)
    @NotNull
    private String matricule;

    @Column(name = "FIRST_NAME", length = 255)
    @NotNull
    private String firstName;

    @Column(name = "LAST_NAME", length = 255)
    @NotNull
    private String lastName;

    @Column(name = "SIGLE", length = 50)
    private String sigle;

    @Lob
    @Column(name = "PICTURE", length = 700)
    private String picture;

    @OrderBy("ID DESC")
    @OneToMany(mappedBy = "refEmployee", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
    private Collection<InOut> inOuts;

    @OrderBy("ID DESC")
    @OneToMany(mappedBy = "refEmployee", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
    private Collection<WeeklyAttendance> weeklyAttendances;

    @OrderBy("ID DESC")
    @OneToMany(mappedBy = "refEmployee", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
    private Collection<Contract> contracts;

    @OrderBy("ID DESC")
    @OneToMany(mappedBy = "refEmployee", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
    private Collection<PersonalAddress> personalAddresses;

    @OrderBy("ID DESC")
    @OneToMany(mappedBy = "refEmployee", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
    private Collection<ProfessionalAddress> professionalAddresses;

    @OrderBy("ID DESC")
    @OneToMany(mappedBy = "refEmployee", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
    private Collection<AdministrativeAssignement> administrativeAssignements;

    @OrderBy("ID DESC")
    @OneToMany(mappedBy = "refEmployee", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
    private Collection<Responsible> responsibles;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "REF_EMPLOYEE_STATUS")
    @NotNull
    private EmployeeStatus refEmployeeStatus;

    @OrderBy("ID DESC")
    @OneToMany(mappedBy = "refEmployee", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
    private Collection<EmployeeHistory> histories;

    @OrderBy("ID DESC")
    @OneToMany(mappedBy = "refEmployee", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
    private Collection<WorkPlace> workPlaces;

    // All getters & setters

}

和EmployeeRepository类

package com.intranet.si.dao.hr;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.intranet.si.model.hr.Employee;

public interface EmployeeRepository extends JpaRepository<Employee, String>, JpaSpecificationExecutor<Employee> {

}

我做错了什么?

0 个答案:

没有答案