import java.util.Map;
/**
* RPC Server
* <p>
* 1:如果bean实现了 BeanNameAware接口,则调用BeanNameAware.setBeanName()
* 2:如果bean实现了BeanFactoryAware接口,则调用BeanFactoryAware.setBeanFactory()
* 3:如果bean实现了ApplicationContextAware接口,则调用ApplicationContextAware.setApplicationContext()
* 4:@PostConstruct 注解指定的初始化方法
* 5:如果bean实现了InitializingBean接口,则调用InitializingBean.afterPropertiesSet()
* 6:调用<bean>的init-method属性指定的初始化方法
* 7:@PreDestroy注解指定的销毁方法 如果bean实现了DiposibleBean接口,则调用DiposibleBean.destory()
* 8:调用<bean>的destroy-method属性指定的初始化方法
*/
public class RpcServer extends NettyServer implements ApplicationContextAware, InitializingBean, DisposableBean {
@Override
public void setApplicationContext(ApplicationContext ctx) throws BeansException {
Map<String, Object> serviceBeanMap = ctx.getBeansWithAnnotation(NettyRpcService.class);
if (MapUtils.isNotEmpty(serviceBeanMap)) {
for (Object serviceBean : serviceBeanMap.values()) {
NettyRpcService nettyRpcService = serviceBean.getClass().getAnnotation(NettyRpcService.class);
String interfaceName = nettyRpcService.value().getName();
String version = nettyRpcService.version();
super.addService(interfaceName, version, serviceBean);
}
}
}
@Override
public void afterPropertiesSet() {
}
@Override
public void destroy() {
}
}
spring常用代码
最新推荐文章于 2023-01-29 14:48:03 发布