0

I have a java-spring application. I use jersey client for some connections to third-party services. I do not use other jersey features (such as features for restfull-services building etc.)

Do I use dependency injection for creating of com.sun.jersey.api.client.Client? (jersey-spring.jar) Or should I call

Client client = Client.create();

each time when I need to use it?

Thanks for advice.

UPDATE: Solution for java-based configuration:

We can define the bean:

@Bean
public Client mailClient() {
    return Client.create();
}

Then we can use it:

@Autowired
private Client mailClient;
Nikolay Shabak
  • 576
  • 1
  • 7
  • 18

1 Answers1

0

You can not directly autowire jersey client as it's implementation will not be found on your component scans, nor in my opinion it makes sense as you can always create a wrapper around your client according to your business needs, and autowire that at your other components as required.

If you are actively using spring it generally makes sense for letting spring to manage your bean lifecycles. Using spring container would also enable you to integrate other spring solutions such as spring-aop to your project components as time progresses and business requirements changes.

Pumpkin
  • 1,993
  • 3
  • 26
  • 32