简体   繁体   English

夸克斯。 从第三方库注册 CDI Beans 类

[英]Quarkus. Registering CDI Beans classes from a third party library

I'm using quarkus to implement a rest-api defined in a 3rd party library.我正在使用 quarkus 来实现在第 3 方库中定义的 rest-api。 This library contains providers that implement ParamConverterProvider, ExceptionMapper, ConstraintValidator, a default implementation of resource interfaces, and so on.该库包含实现 ParamConverterProvider、ExceptionMapper、ConstraintValidator、资源接口的默认实现等的提供程序。 The library is missing beans.xml and jandex index.该库缺少 beans.xml 和 jandex 索引。

Problem: It is required to selectively initialize some of the classes present in the library.问题:需要有选择地初始化库中存在的一些类。 Please advise how this can be done.请告知如何做到这一点。

What I tried:我尝试了什么:

  1. Initialization of all beans of the quarkus.index-dependency property library. quarkus.index-dependency 属性库的所有 bean 的初始化。 The method is not suitable, because there are many providers in the library that do not require.该方法不适合,因为库中有许多不需要的提供程序。

  2. These and the following methods do not work:这些和以下方法不起作用:

@ApplicationScoped
public class AppConfig extends ResourceConfig {
    public AppConfig() {
        register(UnsupportedOperationExceptionMapper.class);
    } 
@ApplicationScoped
public class MyResteasyBootstrap extends ResteasyBootstrap {
    @Override
    public void contextInitialized(ServletContextEvent event) {
        super.contextInitialized(event);
        ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
        factory.registerProvider(UnexpectedErrorExceptionMapper.class);
    }
@ApplicationScoped
public class MyContextResolver implements ContextResolver<ResteasyProviderFactory> {
    private ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
    @PostConstruct
    void initialize() {
        factory.registerProvider(UnsupportedOperationExceptionMapper.class);
    }
    @Override
    public ResteasyProviderFactory getContext(Class type) {
        return factory;
    }
@QuarkusMain
public class MyQuarkusApplication {
    public static void main(String ... args) {
        ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
        factory.registerProvider(UnsupportedOperationExceptionMapper.class);
        Quarkus.run(args);
    }
}

I created a ticket on gihub, in which they suggested 2 options for solving the problem, both were useful for different situations.我在 gihub 上创建了一张票,他们在其中提出了 2 个解决问题的选项,它们都适用于不同的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM