Deepa
Deepa

Reputation: 21

Use Jersey Filter in Spring Boot Jersey

I have a Jersey rest API which we are planning to migrate to Spring boot.

I have a filter that implements ContainerRequestFilter and had @Provider annotation in the filter. I registered the filter in ResourceConfig. But still i don't see the filter executing.

However I do get a warning message:- A provider "My Filter class" registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider "My Filter class" will be ignored.

I wanted to use jersey as servlet so changing the jersey to behave as filter is not working for my app.

Can someone help me on this?

Here is my code

Jersey filter

@Provider
public class CustomJerseyLoggingFilter implements ContainerRequestFilter, ContainerResponseFilter {

    @Override
    public ContainerRequest filter(ContainerRequest request) { }

    @Override
    public ContainerResponse filter(ContainerRequest request, ContainerResponse response) { }
}

@Component
public class JerseyConfig extends ResourceConfig {

    public JerseyConfig() {
         register(CustomJerseyLoggingFilter.class);
    }
}

Upvotes: 2

Views: 8174

Answers (1)

Paul Samsotha
Paul Samsotha

Reputation: 209012

You're implementing the wrong ContainerRequestFilter. The one you are using is from Jersey 1.x. I don't know why you even have Jersey 1.x jars in your project. The ContainerRequestFilter (for 2.x) that you should be implementing is

javax.ws.rs.container.ContainerRequestFilter javax.ws.rs.container.ContainerResponseFilter

Upvotes: 4

Related Questions