注册 X
提交 注:点击提交后系统会发送邮件到邮箱验证!(仅支持中国大陆邮箱)
我已阅读并同意 服务条款
首页 > IT技术笔记 > 查看笔记

Spring mvc项目当系统启动时自动调用某个方法(初始化)

1、添加WebContextListener.java

11455754677.png

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.controller.netty.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、添加配置内容

1145575467712.png

4、最后启动tomcat。

1145575467713.png



	        
			
	      

 打赏        分享



评论

邮箱: 昵称:
\n