【发布时间】:2022-08-03 20:48:25
【问题描述】:
在我的 Spring Boot 应用程序中,我们正在连接到我们的 oracle 数据库。 尝试连接数据库 2-3 次后,如果数据库连接失败,我希望我的应用程序自动关闭。 我该怎么做?
标签: java spring-boot
在我的 Spring Boot 应用程序中,我们正在连接到我们的 oracle 数据库。 尝试连接数据库 2-3 次后,如果数据库连接失败,我希望我的应用程序自动关闭。 我该怎么做?
标签: java spring-boot
方法很少,但一种快速的方法是使用 SpringApplication 的exit 方法。
public YourClass{
@Autowired
ApplicationContext ctx;
public dbconnectivityCheck{
//if connection attempts failed
SpringApplication.exit(ctx);
}
}
【讨论】:
however my when i am trying to run my project it is not working 的意思
SpringApplication.run(Your_Application.class, args).close();使用它来关闭上下文并释放所有资源。
【讨论】: