Listener中注入Service

package com.rratchet.scala;


import com.rratchet.scala.entity.VehicleLoadDataEntity;
import com.rratchet.scala.server.MinaServer;
import com.rratchet.scala.service.DllServiceUtils;
import com.rratchet.scala.service.VehicleLoadDataService;
import com.rratchet.scala.util.Const;
import org.apache.log4j.Logger;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.context.support.XmlWebApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.List;

public class ServerListener implements ServletContextListener {

	private static Logger logger = Logger.getLogger(MinaServer.class);

	private TestService testService;

    @Override
	public void contextDestroyed(ServletContextEvent arg0) {
	}

	// tomcat启动后就会执行该方法
	@Override
	public void contextInitialized(ServletContextEvent arg0) {
	
		
		try {
			XmlWebApplicationContext cxt = (XmlWebApplicationContext) WebApplicationContextUtils.getWebApplicationContext(arg0.getServletContext());
			testService= (VehicleLoadDataService) cxt.getBean("testService");
			
		}catch (Exception e){
			logger.info(">>>>>>>>>>>>>:"+e.getMessage());
		}

	}

	

猜你喜欢

转载自blog.csdn.net/rumengqiang/article/details/82685859