0

We are working mainly with Spring application integrating jersey, we can add @Provider for Exception Providers and Filters (as ContainerRequestFilter)

Can adding @Provider cause problems while using Spring's initialization AnnotationConfigWebApplicationContext or it will be simply ignored?

I didn't find any @Provider in Spring with Jersey tutorial of @PaulSamsotha

I understand @Provider meaning, Currently we aren't using @Provider (and maybe have no reason to)

Marks an implementation of an extension interface that should be discoverable by JAX-RS runtime during a provider scanning phase.

Is @Provider redundant when using Spring managed beans?

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • Are you making these providers Spring beans? It's an interesting question. I would need to do some testing to figure out the answer. But personally, I avoid making the providers Spring components. You can inject Spring services into the providers without the providers being Spring beans. The only thing you can't do is use Spring AOP and inject Spring `@Value`s into the providers (if they are not Spring beans). If you don't need that, I don't see any good reason to make them Spring beans. Just let Jersey handle the lifecycle. – Paul Samsotha Jan 12 '19 at 05:57
  • @PaulSamsotha currently not, but someone might consider it – Ori Marko Jan 12 '19 at 07:30
  • I don't think it will cause a problem when integrating with Spring but you need to register the tax-rs resource config with Spring. Please check the link - https://www.thetechnojournals.com/2019/11/how-to-handle-exceptions-in-rest.html – Ashok Prajapati Nov 17 '19 at 13:21
  • @AshokPrajapati But I have Spring component scan, why I need to add also jersey scanning, what will be the benefit? – Ori Marko Nov 17 '19 at 13:25
  • @user7294900 ComponentScan will scan all spring components, configuration or beans but for jax-rs you just need to create a spring bean for ResourceConfig class which knows about jax-rs components. Seems, spring is not able to identify the jersey Provider without resource config. – Ashok Prajapati Nov 17 '19 at 13:33

0 Answers0