本文共 823 字,大约阅读时间需要 2 分钟。
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;@Servicepublic 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。