@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
log.info("Configuring remote services");
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
ApplicationContext coreContext = context.getParent();
Map<String,Object> services = coreContext.getBeansWithAnnotation(Service.class);
for (Map.Entry<String, Object> entry : services.entrySet()) {
String serviceName = entry.getKey();
Object service = entry.getValue();
List<Class> serviceInterfaces = new ArrayList<>();
List<Class> interfaces = ClassUtils.getAllInterfaces(service.getClass());
for (Class intf : interfaces) {
if (intf.getName().endsWith("Service"))
serviceInterfaces.add(intf);
}
String intfName = null;
if (serviceInterfaces.size() == 0) {
log.error("Bean " + serviceName + " has @Service annotation but no interfaces named '*Service'. Ignoring it.");
} else if (serviceInterfaces.size() > 1) {
intfName = findLowestSubclassName(serviceInterfaces);
if (intfName == null)
log.error("Bean " + serviceName + " has @Service annotation and more than one interface named '*Service', " +
"but these interfaces are not from the same hierarchy. Ignoring it.");
} else {
intfName = serviceInterfaces.get(0).getName();
}
if (intfName != null) {
BeanDefinition definition = new RootBeanDefinition(HttpServiceExporter.class);
MutablePropertyValues propertyValues = definition.getPropertyValues();
propertyValues.add("service", service);
propertyValues.add("serviceInterface", intfName);
registry.registerBeanDefinition("/" + serviceName, definition);
log.debug("Bean " + serviceName + " configured for export via HTTP");
}
}
}
RemoteServicesBeanCreator.java 文件源码
java
阅读 37
收藏 0
点赞 0
评论 0
项目:cuba
作者:
评论列表
文章目录