[英]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中工作,并且在打包后不工作,因此您可以尝试以下操作:
spring-maven-plugin
to package your application. spring-maven-plugin
打包您的应用程序。 @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. @Entity
. @Entity
注释。 @EnableJpaRespotories
in one of your configuration files but make sure it is configured as well. @EnableJpaRespotories
,但请确保也对其进行了配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.