Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个基于 Spring 的 webapp,它使用 Hibernate 保存数据。部署服务时出现的默认网页会立即对数据发出 ajax 请求。因此,如果数据尚不存在,则需要对其进行提取和持久化。我想确保在部署服务时,在春天来临之前,tomcat 提供我的网页,我可以执行代码来获取和保存我的数据。
我认为常规上下文侦听器可能会解决问题,但我不知道是否有任何保证它会在其他所有内容初始化之前完成。春天有什么东西可以做到这一点吗?或者上下文侦听器会解决问题吗?
您可以使用spring的应用程序事件(上下文事件),请参阅文档ContextStartedEvent
ContextStartedEvent