You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "gMan1990 (GitHub)" <gi...@apache.org> on 2018/11/27 05:49:41 UTC

[GitHub] [incubator-dubbo] gMan1990 opened issue #2835: 讨论: 配置

1. 随便选个老版本:2.5.3
https://github.com/apache/incubator-dubbo/blob/ebbdbaa38420019a9e2332caef776e60b892c525/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/schema/DubboNamespaceHandler.java#L54
老的文档:
https://github.com/alibaba/dubbo-doc-static/blob/d4df1111a79ebb14be22b6a02d3e7526ff6b8e9e/Annotation%2BConfig-zh.htm#L838
```
<!-- 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类 -->
<dubbo:annotation package="com.foo.bar.action" />
```
2. 新版本:2.6.3
https://github.com/apache/incubator-dubbo/blob/6ce7b11f982c5f7beb2ac5897fb33d48da357ada/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/schema/DubboNamespaceHandler.java#L53
然后我看AnnotationBeanDefinitionParser里面会注册ReferenceAnnotationBeanPostProcessor,里面的findFieldReferenceMetadata:
https://github.com/apache/incubator-dubbo/blob/6ce7b11f982c5f7beb2ac5897fb33d48da357ada/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java#L108
```java
ReflectionUtils.doWithFields(beanClass, new ReflectionUtils.FieldCallback() {
    @Override
    public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
        Reference reference = getAnnotation(field, Reference.class);
```

Q: 这个beanClass我断点到org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator也会传进来,
```扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类```,好像和这句话不符合。有人了解吗?不吝赐教,谢谢

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2835 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] gMan1990 commented on issue #2835: 讨论: 配置

Posted by "gMan1990 (GitHub)" <gi...@apache.org>.
@gudegg 就一个问题,我重新编辑了下,问题地方我加粗了。我是问
我写了<dubbo:annotation package="x.x.x.x" />
按照以前老文档的说法```扫描注解包路径,多个包用逗号分隔,不填pacakge表示```
但我用2.6.3测试发现文中列出的class都会执行到```ReflectionUtils.doWithFields```有的还执行3-4次。当然我知道新的jar新的改动。所以我就问问<dubbo:annotation package现在的逻辑之类的。

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2835 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] carryxyh commented on issue #2835: 讨论: 配置

Posted by "carryxyh (GitHub)" <gi...@apache.org>.
暂时关闭这个issue。如果有其他讨论可以重新开启。

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2835 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] gMan1990 commented on issue #2835: 讨论: 配置

Posted by "gMan1990 (GitHub)" <gi...@apache.org>.
@gudegg 就一个问题,我重新编辑了下,问题地方我加粗了。我是问
我写了<dubbo:annotation package="x.x.x.x" />,按照以前老文档的说法
```扫描注解包路径,多个包用逗号分隔,不填pacakge表示```
可能只有我定义的package下的class才会执行到```ReflectionUtils.doWithFields```
但我用2.6.3测试发现文中列出的class都会执行到```ReflectionUtils.doWithFields```有的还执行3-4次。当然我知道新的版本新的改进。所以我就问问<dubbo:annotation package现在的逻辑之类的。

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2835 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] carryxyh closed issue #2835: 讨论: 配置

Posted by "carryxyh (GitHub)" <gi...@apache.org>.
[ issue closed by carryxyh ]

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2835 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] carryxyh commented on issue #2835: 讨论: 配置

Posted by "carryxyh (GitHub)" <gi...@apache.org>.
如果没有其他讨论,我会关闭这个issue

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2835 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] gudegg commented on issue #2835: 讨论: 配置

Posted by "gudegg (GitHub)" <gi...@apache.org>.
问题1:可以去看下`org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor#postProcessMergedBeanDefinition`何时被调用就明白了
<img width="896" alt="dubbo" src="https://user-images.githubusercontent.com/13344666/49079075-aa2fee80-f27a-11e8-8906-e65efff22f7d.png">
作者说过@Reference实现和@Autowired实现相似,参考了AutowiredAnnotationBeanPostProcessor
问题2:
注解不填写时扫描包路径,看`org.apache.dubbo.config.spring.context.annotation.DubboComponentScanRegistrar#getPackagesToScan`
```java
        if (packagesToScan.isEmpty()) {
            return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName()));
        }
```

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2835 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] gudegg commented on issue #2835: 讨论: 配置

Posted by "gudegg (GitHub)" <gi...@apache.org>.
@gMan1990 在2.5.3低版本时,你不写package`@Service`是不会被扫描发布的,新版本也一样(ps:你用xml不是用注解),你说的`ReflectionUtils.doWithFields`是新版本在引用时用到,@Reference他是不依赖你填写的package,他依赖于当前类是否被注入spring容器,写不写package无关紧要

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2835 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org