forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@service and @reference issues on <dubbo:annotation>
To resolve alibaba/dubbo apache#1125
- Loading branch information
1 parent
adfbff3
commit 3e19343
Showing
5 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
.../src/main/java/com/alibaba/dubbo/config/spring/schema/AnnotationBeanDefinitionParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.alibaba.dubbo.config.spring.schema; | ||
|
||
import com.alibaba.dubbo.config.spring.AnnotationBean; | ||
import com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; | ||
import com.alibaba.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor; | ||
import com.alibaba.dubbo.config.spring.util.BeanRegistrar; | ||
import org.springframework.beans.factory.BeanFactory; | ||
import org.springframework.beans.factory.config.BeanDefinition; | ||
import org.springframework.beans.factory.support.BeanDefinitionBuilder; | ||
import org.springframework.beans.factory.support.BeanDefinitionRegistry; | ||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; | ||
import org.springframework.beans.factory.xml.BeanDefinitionParser; | ||
import org.springframework.beans.factory.xml.ParserContext; | ||
import org.w3c.dom.Element; | ||
|
||
import static org.springframework.util.StringUtils.commaDelimitedListToStringArray; | ||
import static org.springframework.util.StringUtils.trimArrayElements; | ||
|
||
/** | ||
* {@link AnnotationBean} {@link BeanDefinitionParser} | ||
* | ||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a> | ||
* @see ServiceAnnotationBeanPostProcessor | ||
* @see ReferenceAnnotationBeanPostProcessor | ||
* @since 2.5.9 | ||
*/ | ||
public class AnnotationBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { | ||
|
||
/** | ||
* parse | ||
* <prev> | ||
* <dubbo:annotation package="" /> | ||
* </prev> | ||
* | ||
* @param element | ||
* @param parserContext | ||
* @param builder | ||
*/ | ||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { | ||
|
||
String packageToScan = element.getAttribute("package"); | ||
|
||
String[] packagesToScan = trimArrayElements(commaDelimitedListToStringArray(packageToScan)); | ||
|
||
builder.addConstructorArgValue(packagesToScan); | ||
|
||
builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); | ||
|
||
// Registers ReferenceAnnotationBeanPostProcessor | ||
registerReferenceAnnotationBeanPostProcessor(parserContext.getRegistry()); | ||
|
||
} | ||
|
||
/** | ||
* Registers {@link ReferenceAnnotationBeanPostProcessor} into {@link BeanFactory} | ||
* | ||
* @param registry {@link BeanDefinitionRegistry} | ||
*/ | ||
private void registerReferenceAnnotationBeanPostProcessor(BeanDefinitionRegistry registry) { | ||
|
||
// Register @Reference Annotation Bean Processor | ||
BeanRegistrar.registerInfrastructureBean(registry, | ||
ReferenceAnnotationBeanPostProcessor.BEAN_NAME, ReferenceAnnotationBeanPostProcessor.class); | ||
|
||
} | ||
|
||
protected Class<?> getBeanClass(Element element) { | ||
return ServiceAnnotationBeanPostProcessor.class; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters