我的环境是Spring 环境。
建立一个Servlet 来实现。
web.xml
<servlet>
<display-name>ProjectInitServlet</display-name>
<servlet-name>ProjectInitServlet</servlet-name>
<servlet-class>com.server.utils.ProjectInitServlet</servlet-class>
<load-on-startup>5</load-on-startup>//这里5代表最后加载
</servlet>
<servlet-mapping>
<servlet-name>ProjectInitServlet</servlet-name>
<url-pattern>/ProjectInitServlet</url-pattern>
</servlet-mapping>
ProjectInitServlet.java
public class ProjectInitServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void init() throws ServletException {
System.out.println("+++项目启动初始化操作开始+++++");
ApplicationContext appContext = DefaultApplicationContextAware.getContext();
WfRuCsaService bean = appContext.getBean(WfRuCsaService.class);
List<WorkflowRuCsa> findAll = bean.findAll();
System.out.println(findAll.size());
System.out.println("+++项目启动初始化操作结束+++++");
}
}