我正在开发一个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]
我做错了什么?
答案 0 :(得分:0)
我可以看到repository
所以我假设您使用spring-data
。奇怪的是,它在maven中工作,在包装后无法工作,因此您可以尝试以下方法:
spring-maven-plugin
打包申请。@EntityScan("com.intranet.si.model.hr")
(也可以com.intranet.si.model
以递归方式捕获包和子包中的所有模型)到一个配置类或应用程序类(用{注释的那个) {1}})。这将通知spring + hibernate扫描实体的位置。另外,请确保您的实体使用@SpringBootApplication
注释。@Entity
,但也要确保它已配置好。