Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyblitz committed Apr 23, 2018
1 parent a7d176f commit 2eff02d
Showing 1 changed file with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
public class ServiceAnnotationBeanPostProcessor implements BeanDefinitionRegistryPostProcessor, EnvironmentAware,
ResourceLoaderAware, BeanClassLoaderAware {

private static final String SEPARATOR = ":";

private final Logger logger = LoggerFactory.getLogger(getClass());

private final Set<String> packagesToScan;
Expand Down Expand Up @@ -254,7 +256,7 @@ private void registerServiceBean(BeanDefinitionHolder beanDefinitionHolder, Bean
buildServiceBeanDefinition(service, interfaceClass, annotatedServiceBeanName);

// ServiceBean Bean name
String beanName = generateServiceBeanName(interfaceClass, annotatedServiceBeanName);
String beanName = generateServiceBeanName(service, interfaceClass, annotatedServiceBeanName);

if (scanner.checkCandidate(beanName, serviceBeanDefinition)) { // check duplicated candidate bean
registry.registerBeanDefinition(beanName, serviceBeanDefinition);
Expand All @@ -279,14 +281,35 @@ private void registerServiceBean(BeanDefinitionHolder beanDefinitionHolder, Bean
/**
* Generates the bean name of {@link ServiceBean}
*
* @param service
* @param interfaceClass the class of interface annotated {@link Service}
* @param annotatedServiceBeanName the bean name of annotated {@link Service}
* @return ServiceBean@interfaceClassName#annotatedServiceBeanName
* @since 2.5.9
*/
private String generateServiceBeanName(Class<?> interfaceClass, String annotatedServiceBeanName) {
private String generateServiceBeanName(Service service, Class<?> interfaceClass, String annotatedServiceBeanName) {

StringBuilder beanNameBuilder = new StringBuilder(ServiceBean.class.getSimpleName());

beanNameBuilder.append(SEPARATOR).append(annotatedServiceBeanName);

String interfaceClassName = interfaceClass.getName();

beanNameBuilder.append(SEPARATOR).append(interfaceClassName);

String version = service.version();

return "ServiceBean@" + interfaceClass.getName() + "#" + annotatedServiceBeanName;
if (StringUtils.hasText(version)) {
beanNameBuilder.append(SEPARATOR).append(version);
}

String group = service.group();

if (StringUtils.hasText(group)) {
beanNameBuilder.append(SEPARATOR).append(group);
}

return beanNameBuilder.toString();

}

Expand Down Expand Up @@ -423,7 +446,7 @@ private AbstractBeanDefinition buildServiceBeanDefinition(Service service, Class

List<RuntimeBeanReference> protocolRuntimeBeanReferences = toRuntimeBeanReferences(protocolConfigBeanNames);

if (!registryRuntimeBeanReferences.isEmpty()) {
if (!protocolRuntimeBeanReferences.isEmpty()) {
builder.addPropertyValue("protocols", protocolRuntimeBeanReferences);
}

Expand Down

0 comments on commit 2eff02d

Please sign in to comment.