[apache/dubbo]@DubboComponentScan注解在消费端扫描包时扫描的是 @Service注解??不是@Reference注解??

2024-04-11 247 views
2

@DubboComponentScan注解在消费端扫描包时扫描的是 @Service注解??不是@Reference注解?? 启动时报 DubboComponentScanRegistrar-85]-[main]-[INFO] 0 annotated @Service Components { [] }

回答

1

我也是用的注解方式,我是这么配置的:

@Configuration @ComponentScan( basePackages = { "/com.xxxx.**.provider" }, useDefaultFilters = false, includeFilters = { @ComponentScan.Filter( type = FilterType.ANNOTATION, value = Service.class ), @ComponentScan.Filter( type = FilterType.ANNOTATION, value = Component.class ) } ) public class DubboSOAConfig { @Bean public AnnotationBean AnnotationBean() { // AnnotationBean annotationBean = new AnnotationBean(); // annotationBean.setPackage(DEFAULT_SCAN_PACKAGE); // return annotationBean; return new AnnotationBean(); } }

3

@663534597 你好,消费端的注解是怎么配置的??

1

不用配置,不过不能在controller 里 用@Referencef

9

@Configuration @ComponentScan( basePackages = { "/com.xxxx.**.provider" }, useDefaultFilters = false, includeFilters = { @ComponentScan.Filter( type = FilterType.ANNOTATION, value = Service.class ) } ) public class DubboSOAConfig { @Bean public AnnotationBean AnnotationBean() { // AnnotationBean annotationBean = new AnnotationBean(); // annotationBean.setPackage(DEFAULT_SCAN_PACKAGE); // return annotationBean; return new AnnotationBean(); } }

package com.xxx.fusion.route.submerc.provider;

import com.alibaba.dubbo.config.annotation.Service; import com.xxx.fusion.route.submerc.api.IRouteSubmercService; import com.icitic.fusion.route.submerc.service.RouteSubMercImpl; import org.springframework.beans.factory.annotation.Autowired;

@Service(version = "1.0.0", group="WX") public class RouteSubMercServiceProvider implements IRouteSubmercService {

@Autowired
private RouteSubMercImpl routeSubmerc;

@Override
public AvailableResult<RTMercAddResVO> addMerc(RTMercAddReqVO rtMercAddReqVO) {
    return routeSubmerc.addMerc(rtMercAddReqVO);
}

}

package com.xxx.fusion.route.submerc.service;

import com.alibaba.dubbo.config.annotation.Reference; import com.xxx.fusion.route.submerc.api.IRouteSubmercService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList; import java.util.List;

/**

  • 路由通道服务商户进谏模块
  • Created by sunny on 2017-08-16. */ @Component public class RouteSubMercImpl {

    private static Logger logger = LoggerFactory.getLogger(RouteSubMercImpl.class);

    @Reference(version = "1.0.0", group="WX") private IRouteSubmercService routeSubmercService;

    public AvailableResult addMerc(RTMercAddReqVO rtMercAddReqVO) { ... routeSubmercService.xxxx(); ... } }

6

@663534597 @Component("UserService") public class UserService{ @Reference private UserServiceI service; } 我在消费端是这么写的,tomcat启动的时候日志里面没有dubbo相关信息,zk也没注册进去

3

消费端工程也需要增加@componentscanz配置才能识别@Reference

8

@Reference 类似于 @Autowired 一样,首先其申明的类必须被 Spring 上下文当做一个Bean,因此,Dubbo 并没有直接将 @Reference 字段所在的类提升成 Bean。

综上所述,这并不是一个问题,而是用法不当!