简体   繁体   English

无法部署Spring Boot Jar应用程序

[英]Unable to deploy spring boot jar application

I'm developping a spring boot application and it works fine when I run the command: 我正在开发一个Spring Boot应用程序,当我运行命令时它可以正常工作:

mvn spring-boot:run

But when deploying jar file with the command: 但是,使用以下命令部署jar文件时:

java -jar target\\jarfile.jar

I get the following error: 我收到以下错误:

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
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

What am I doing wrong? 我究竟做错了什么?

I can see a repository so I assume you use spring-data . 我可以看到一个repository所以我假设您使用spring-data It is strange that it works in maven and not working after packaging so you can try the following: 奇怪的是,它可以在Maven中工作,并且在打包后不工作,因此您可以尝试以下操作:

  1. Check that you use spring-maven-plugin to package your application. 检查您是否使用spring-maven-plugin打包您的应用程序。
  2. Try to add @EntityScan("com.intranet.si.model.hr") (can also be com.intranet.si.model to recursivly catch all models in the package and sub-packages) to one of your configuration classes or to the application class (the one annotated with @SpringBootApplication ). 尝试将@EntityScan("com.intranet.si.model.hr") (也可以是com.intranet.si.model来递归地捕获包和子包中的所有模型)添加到配置类之一或应用程序类(用@SpringBootApplication注释的@SpringBootApplication )。 This will notify spring + hibernate where to scan for entities. 这将通知spring + hibernate在哪里扫描实体。 Also make sure your entity is annotated with @Entity . 还要确保您的实体使用@Entity注释。
  3. I guess that you already have @EnableJpaRespotories in one of your configuration files but make sure it is configured as well. 我猜您其中一个配置文件中已经有@EnableJpaRespotories ,但请确保也对其进行了配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM