What is Spring boot's version of @Assisted

470 Views Asked by At

I'm wondering how to convert Guice's @Assisted annotation into spring boot in Java. For example I have this code:

@Inject
public Merge(@Named(Conf.MkvFields.CHAININPUT_DELAY) String chainInputDelay,
    @Named(Conf.MkvFields.REAL_TIME_PROCESSING),
    @Assisted MergeDefinition mergeDefinition) {

For example you'd have:

public interface MergeFactory { 
    public Merge createMerge(@Assisted MergeDefinition mergeDefinition);    
}

And then you'd have:

        install(new FactoryModuleBuilder().build(MergeFactory.class));

And:

mergeFactory.createMerge(mergeDefinition));

I know how to convert @Inject and @Named, but I've been doing some research on the @Assisted but can't find anything? Is it possible? If so how would I do it?

1

There are 1 best solutions below

1
Ameera Najah Kv On

Spring has no equivalent to the Guice FactoryModuleBuilder. The closest equivalent would be a Spring @Configuration class that provides a factory bean that implements a factory interface whose methods accept arbitrary arguments from the application. Please refer the following link for details: What is the Spring equivalent to FactoryModuleBuilder, @AssistedInject, and @Assisted in Guice?