1. 程式人生 > >Spring mvc + mybatis web專案當系統啟動時自動呼叫某個方法

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.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、新增配置內容


4、最後啟動tomcat。