- ubuntu
- 尝试在 ubuntu 上部署 spring boot 应用程序时出现 'UnsatisfiedDependencyException:在 URL 中定义名为 'eventService' 的 bean 时出错'
尝试在 ubuntu 上部署 spring boot 应用程序时出现 'UnsatisfiedDependencyException:在 URL 中定义名为 'eventService' 的 bean 时出错'
155
0
当我在 IntelliJ IDEA 的开发机器上运行该项目时,一切都运行正常,没有任何错误,但是当我尝试将其打包并部署到运行 Ubuntu 24.04 的服务器上时,我得到了
当我在 IntelliJ IDEA 中的开发机器上运行该项目时,一切都运行正常,没有任何错误,但是当我尝试将其打包并部署到运行 Ubuntu 24.04 的服务器上时,我收到这个奇怪的错误:
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 failed
Jun 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
这是错误中提到的代码(EventRepository):
@Repository
public interface EventRepository extends JpaRepository<Event, String> {
@NonNull
Optional<Event> findById(@NonNull String id);
}
还有自动装配的部分(EventService):
@Service
@Slf4j
@Transactional(rollbackOn = Exception.class)
@AllArgsConstructor
public class EventService {
@Autowired
private EventRepository eventRepository;
当我尝试在同一台机器上使用与在 IntelliJ 中正常运行相同的 jdk 运行编译后的 jar 时,也会出现此错误。
我使用的命令是 C:\Users\MyUser\.jdks\openjdk-22.0.1\bin\java.exe -jar .\animalshelter.jar
收藏的用户(0)
X
正在加载信息~