Spring mvc + mybatis web project automatically calls a method when the system starts

1. Add WebContextListener.java

2. File content

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. Add configuration content



4. Finally start tomcat.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325813518&siteId=291194637