如何在Spring Boot中创建/配置bean期间捕获任何异常?
答案 0 :(得分:0)
您可以尝试监听实现了ApplicationFailedEventListener
的应用程序启动失败,然后获取BeanDefinitionStoreException
:
@Component
public class ApplicationFailedEventListener implements ApplicationListener<ApplicationFailedEvent> {
@Override
public void onApplicationEvent(ApplicationFailedEvent applicationFailedEvent) {
// Get the exception.
Throwable yourException = applicationFailedEvent.getException();
// Check if the exception was a BeanDefinitionStoreException and do whatever...
}
}
希望它有所帮助! :)