java - Spring and Jersey Filter - Provider or Component? -


i'm trying determine spring-boot, jersey , how jersey , spring-boot contexts relate 1 another.

@component public class corsfilter implements filter {       public void dofilter(servletrequest req, servletresponse res, filterchain chain) throws ioexception, servletexception {         httpservletresponse response = (httpservletresponse) res;         response.setheader("access-control-allow-origin", "*");         response.setheader("access-control-allow-methods", "post, get, options, delete");         response.setheader("access-control-max-age", "3600");         response.setheader("access-control-allow-headers", "x-requested-with");         chain.dofilter(req, res);     }      public void init(filterconfig filterconfig) {     }      public void destroy() {     }   } 

when have labeled @provider , make jersey in package lives it, doesn't find it. works when make @component.

@configuration @applicationpath("/api/v1") public class jerseyconfig extends resourceconfig{      public jerseyconfig() {         // doesnt find corsfilter  provider         this.packages("com.mypackage.rest");     }   } 

does @configuration annotation make jerseycontext spring bean? , spring injects corsfilter because finds component of filter type? happening here?

you implementing servlet filter (implements filter) means servlet container instantiating filter. when provide @component annotation, still servlet container initializes filter. spring context aware of using contextloader listener.

in jersey filter should implement containerrequestfilter or containerresponsefilter jersey configs applied filters url path. since used servlet filter should configure manually.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -