@Component public class NettyClient implements ApplicationContextAware { NettyClientHandler nettyClientHandler; /** * 当前 ApplicationContent 后面注入用 */ private ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } public void doConnect() { nettyClientHandler =applicationContext.getBean(NettyClientHandler.class); ....pipeline.addLast(nettyClientHandler); } }
@Component public class NettyClient implements ApplicationContextAware { @Autowired NettyClientHandler nettyClientHandler; public void doConnect() { ....pipeline.addLast(nettyClientHandler); } }