quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.73k stars 2.67k forks source link

Support for ObjectProvider<T> from Spring #10901

Open chirdeeptomar opened 4 years ago

chirdeeptomar commented 4 years ago

Description

I have the following Spring bean that use ObjectProvider in one of the gradle modules, I have Quarkus as the web layer. Quarkus is unable to resolve ObjectProvider dependency. I have set up beans.xml, everything works until I add the AppConfig as below.

@Configuration
public class AppConfig {

    @Bean
    public Customer customer(ObjectProvider<CustomerBuilder> builder) {
        return new Customer();
    }
}

CustomerBuilder.java

@Component
public class CustomerBuilder {
}

Quarkus Graphql module

@GraphQLApi
public class ExampleResource {
    @Inject
    TestService service;

    @Query("allFilms")
    @Description("Get all Films from a galaxy far far away")
    public boolean getAllFilms() {
        return service.test();
    }
}

Error

`Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.springframework.beans.factory.ObjectProvider<com.exa mple.demo.CustomerBuilder> and qualifiers [@Default]

quarkusbot commented 4 years ago

/cc @geoand

vietk commented 4 years ago

Quarkus Spring DI support merely transforms Spring annotations into CDI annotations, here it's more about providing an alternative implementation of Spring DI itself, which can be tedious if you one want to fill all the gaps.

Maybe you have to consider switching to CDI for some part of your code, i.e: mixing CDI and SpringDI code ?

rmarting commented 4 years ago

Same issue if the original Spring application code uses ObjectFactory:

@Configuration
public class KafkaConfig {
    @Bean
    public Producer<String, Message> createProducer() { /* Config stuff */}
}

And in my @Service class:

@Service
public class MessageService {

    private ObjectFactory<Producer<String, Message>> producer;

    public MessageService(ObjectFactory<Producer<String, Message>> producer) {
        this.producer = producer;
    }
}

Error stack trace:

Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.springframework.beans.factory.ObjectFactory<org.apache.kafka.clients.producer.Producer<java.lang.String, com.rmarting.kafka.schema.avro.Message>> and qualifiers [@Default]
    - java member: com.rmarting.kafka.service.MessageService#<init>()
    - declared on CLASS bean [types=[com.rmarting.kafka.service.MessageService, java.lang.Object], qualifiers=[@Named(value = "messageService"), @Default, @Any], target=com.rmarting.kafka.service.MessageService]
    at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:504)

In both cases, should we refactor these definitions using CDI instead of Spring DI? Is there any plan to cover these Spring feature?

geoand commented 4 years ago

Hi,

We could most likely offer support for this. If enough people ask, we'll put the effort into it :)