0

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?

DwB
  • 37,124
  • 11
  • 56
  • 82
sunalive
  • 255
  • 4
  • 13
  • [Wait, *what*?](https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/assistedinject/Assisted.html) What does it *do*?? – Makoto Feb 01 '19 at 16:48
  • You can use it when using the factory module builder to create new objects (I think) I've updated my post with an example. – sunalive Feb 01 '19 at 16:52

1 Answers1

0

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?

  • The answer isn't very helpful, it seems to give you half an answer. It doesn't explain how you implement the factory though, as with guice you can create: private final MergeFactory mergeFactory; and initialize it in the constructor, but you can't do that with the answer to that question. Could you explain it to me? – sunalive Feb 04 '19 at 12:05