
Spring mvc + mybatis web项目当系统启动时自动调用某个方法
1、添加WebContextListener.java
2、文件内容
package com.pt.controller.listener; import javax.servlet.ServletContext; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.context.ServletContextAware; import com.pt.controllerty.MyServer; @Service public class WebContextListener implements InitializingBean, ServletContextAware{ @Autowired private MyServer myServer; @Override public void setServletContext(ServletContext servletContext) { try { myServer.bind(1235); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void afterPropertiesSet() throws Exception { // TODO Auto-generated method stub } }3、添加配置内容
4、最后启动tomcat。
👁️ 阅读量:0
© 版权声明:本文《Spring mvc + mybatis web项目当系统启动时自动调用某个方法》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686617029a306570.html。