When I run the project on my development machine in IntelliJ IDEA, everything works perfectly without any errors, but as soon as I try to jar it and deploy it to my server running Ubuntu 24.04, I get this weird error:
Jun 01 20:16:31 raspberrypi5 AnimalShelter[36353]: . ____ _ __ _ _Jun 01 20:16:31 raspberrypi5 AnimalShelter[36353]: /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \Jun 01 20:16:31 raspberrypi5 AnimalShelter[36353]: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \Jun 01 20:16:31 raspberrypi5 AnimalShelter[36353]: \\/ ___)| |_)| | | | | || (_| | ) ) ) )Jun 01 20:16:31 raspberrypi5 AnimalShelter[36353]: ' |____| .__|_| |_|_| |_\__, | / / / /Jun 01 20:16:31 raspberrypi5 AnimalShelter[36353]: =========|_|==============|___/=/_/_/_/Jun 01 20:16:31 raspberrypi5 AnimalShelter[36353]: :: Spring Boot :: (v3.2.5)Jun 01 20:16:31 raspberrypi5 AnimalShelter[36353]: 20:16:31.924 [main] INFO me.fazelukario.animalshelter.AnimalShelterApplication -- Starting AnimalShelterApplication using Java 22-ea with PID 36353 (/root/AnimalShelter/animalshelter.jar started by root in /root/AnimalShelter)Jun 01 20:16:31 raspberrypi5 AnimalShelter[36353]: 20:16:31.930 [main] INFO me.fazelukario.animalshelter.AnimalShelterApplication -- No active profile set, falling back to 1 default profile: "default"Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: 20:16:32.479 [main] WARN org.springframework.context.annotation.AnnotationConfigApplicationContext -- Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eventService' defined in URL [jar:file:/root/AnimalShelter/animalshelter.jar!/me/fazelukario/animalshelter/services/EventService.class]: Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type 'me.fazelukario.animalshelter.repository.EventRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: 20:16:32.487 [main] ERROR org.springframework.boot.SpringApplication -- Application run failedJun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eventService' defined in URL [jar:file:/root/AnimalShelter/animalshelter.jar!/me/fazelukario/animalshelter/services/EventService.class]: Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type 'me.fazelukario.animalshelter.repository.EventRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:795)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:237)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1355)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1192)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:962)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at me.fazelukario.animalshelter.AnimalShelterApplication.main(AnimalShelterApplication.java:10)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'me.fazelukario.animalshelter.repository.EventRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1880)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1406)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1353)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:904)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:782)Jun 01 20:16:32 raspberrypi5 AnimalShelter[36353]: ... 18 common frames omitted
Here's code that mentioned in error (EventRepository):
@Repositorypublic interface EventRepository extends JpaRepository<Event, String> { @NonNull Optional<Event> findById(@NonNull String id);}
Also part where it is autowiring (EventService):
@Service@Slf4j@Transactional(rollbackOn = Exception.class)@AllArgsConstructorpublic class EventService { @Autowired private EventRepository eventRepository;
I also get this error when I try to run the compiled jar on the same machine with the same jdk that I run it normally in IntelliJ.
The command I used is C:\Users\MyUser\.jdks\openjdk-22.0.1\bin\java.exe -jar .\animalshelter.jar