比较贴近生产,详见注释
一、pom.xml
具体太长,详见源码
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.2.Final</version>
</dependency>
二、目录结构
三、AfterSpringBegin
继承了AfterSpringBegin的子类在spring加载成功后,会自动启动
package com.netty.init; import java.util.Timer; import java.util.TimerTask; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; /** * * spring加载后改方法的子类 * */ public abstract class AfterSpringBegin extends TimerTask implements ApplicationListener<ContextRefreshedEvent>{ public void onApplicationEvent(ContextRefreshedEvent event) { // TODO Auto-generated method stub if(event.getApplicationContext().getParent() ==null){ Timer timer = new Timer(); timer.schedule(this, 0); } } }