简体   繁体   中英

Register Filter in CXF Spring Boot

How can I register ContainerResponseFilter/ContainerRequestFilter in CXF? Like Jersey's ResourceConfig.

@Provider
@Priority(value = 2)
public class CorsResponseFilter implements ContainerResponseFilter {

    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
            throws IOException {

        System.out.println("filtered");
    }

}

If you've enabled cxf be adding property cxf.jaxrs.component-scan=true then you Both resources and providers should be part of application context. Hence annotate with @Service or @Component .

@Component
@Provider
@Priority(value = 2)
public class CorsResponseFilter implements ContainerResponseFilter {

    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
            throws IOException {

        System.out.println("filtered");
    }

}

If you are enabling using classes scan make sure provider is part of packages you have given.

cxf.jaxrs.classes-scan=true
cxf.jaxrs.classes-scan-packages=yourpackage where provider is present.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM