读取接口上定义的注释,并使用注释值创建Bean类

时间:2018-12-30 14:05:13

标签: spring spring-boot annotations

我正在尝试从接口上为每个api提供的jaxrs批注动态创建http客户端。

public @interface RestClient {
  String baseUrlKey();  
}


@Component
@RestClient(baseUrlKey="NOTIFICATION")
@Path("/notification/")
public interface NotificationClient {
    @Path("/")
    @POST
    @Produces("application/json")
    @Consumes("application/json")
    public abstract NotificationResponse create(NotificationEntry entry);

}

现在,我正在尝试编写另一个类,以尝试查找所有带@RestClient注释的接口。我似乎找不到任何解决方案。所有应用程序上下文方法似乎都返回可以实例化的类。有什么方法可以加载此接口并动态创建apache http客户端的bean实例并向应用程序上下文注册。

这是bean初始化程序类-

public class RestClientBeanProcessor {

    private static final Logger LOGGER = LoggerFactory.getLogger(RestClientBeanProcessor.class);

    @Autowired
    RestTemplate restTemplate;

    @Autowired
        ApplicationContext applicationContext;


    @PostConstruct
    private void registerClientBeans() {
        Map<String, Object> beans = applicationContext.getBeansWithAnnotation(RestClient.class);
        LOGGER.info("Registering client beans for - " + beans);
    }

} 

我的bean对象为空。 Spring无法告诉我查询所要求的接口列表。

0 个答案:

没有答案