2

How to make the same thing without Spring ? I don't know how to declare the bean using specific constructor.

Usually I would do it with Spring this way, but right now I can't use Spring.

@Configuration public class ClientConfig { @Bean public MyApi myApi() { return Feign.builder().target(MyApi.class, myUrl); } } 

And use injection in another class.

public class AnotherClass { @Inject MyApi myApi; } 

How to "declare" the bean? Today I'm using a singleton and it is 'ugly', so thanks in advance for any advice.

3

1 Answer 1

1

You can use producer method which creates desired injectable bean. It's good practice to put producer methods in separated bean:

@Dependent public class Resources { @Produces @Default public MyApi myApi() { return Feign.builder().target(MyApi.class, myUrl); } } 

you can use @Inject MyApi myApi anywhere you need it then.

For more info see the CDI documentation http://weld.cdi-spec.org/.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.