Spring服务停机时报错 BeanCreationNotAllowedException: Error creating bean with name
时间: 2023-11-02 10:50:33 浏览: 68
BeanCreationNotAllowedException is thrown when a Spring bean is being created during the shutdown phase of the application context. This exception occurs when a bean is being created after the destruction of the application context has already started. This means that the bean creation process is not allowed at this point since the application context is in the process of shutting down.
The Error creating bean with name message can occur due to various reasons, such as:
1. The bean is being created in a lifecycle method that is called during the shutdown phase.
2. The bean is being created in a bean post-processor that is called during the shutdown phase.
3. The bean is being created in a bean factory post-processor that is called during the shutdown phase.
To resolve this issue, you can try the following steps:
1. Check if any of your beans are being created during the shutdown phase and move the creation logic to a different phase.
2. Check if any of your bean post-processors or bean factory post-processors are being called during the shutdown phase and update the logic accordingly.
3. Modify the order of the lifecycle methods to ensure that the shutdown process is executed after all the beans are created.
In general, it is recommended to avoid creating beans during the shutdown phase since it can cause issues like this one. Instead, you should focus on cleaning up resources and releasing any held locks or connections.