在web.xml里面配置监听 项目启动时 直接初始化上下文
init com.james.amy.impl.listener.InitListener
监听类 实现 ServletContextListener 重写 contextInitialized 方法
关键点:获取bean
方法1:
ApplicationContext context=WebApplicationContextUtils.getRequiredWebApplicationContext(servletContextEvent.getServletContext()); SysParamMapper sysParamMapper=(SysParamMapper) context.getBean("sysParamMapper");
方法2:
ContextLoader.getCurrentWebApplicationContext().getBean("pokerRoomService");
扫描时启动一个类的方法:<!-- <bean id="websocketServer" class="com.softisland.jc.poker.socket.WebSocketServer" init-method="start" >
</bean> -->