无法部署spring boot jar应用程序

时间:2018-03-27 09:02:52

标签: java spring-boot deployment executable-jar

我正在开发一个spring boot应用程序,当我运行命令时它可以正常工作:

mvn spring-boot:run

但是在使用以下命令部署jar文件时:

java -jar target\jarfile.jar

我收到以下错误:

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]

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我可以看到repository所以我假设您使用spring-data。奇怪的是,它在maven中工作,在包装后无法工作,因此您可以尝试以下方法:

  1. 检查您是否使用spring-maven-plugin打包申请。
  2. 尝试添加@EntityScan("com.intranet.si.model.hr")(也可以com.intranet.si.model以递归方式捕获包和子包中的所有模型)到一个配置类或应用程序类(用{注释的那个) {1}})。这将通知spring + hibernate扫描实体的位置。另外,请确保您的实体使用@SpringBootApplication注释。
  3. 我猜你的一个配置文件中已经有@Entity,但也要确保它已配置好。
相关问题