I'm developping a spring boot application and it works fine when I run the command:
mvn spring-boot:run
But when deploying jar file with the command:
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
. It is strange that it works in maven and not working after packaging so you can try the following:
spring-maven-plugin
to package your application. @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
). This will notify spring + hibernate where to scan for entities. Also make sure your entity is annotated with @Entity
. @EnableJpaRespotories
in one of your configuration files but make sure it is configured as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.