java - Usage of interceptor in spring -
this situation :
why using interceptor ?
i want write module stores data requests being served @ server. data me in doing data visualizations.
how using currently?
@component public class mycustominterceptor extends handlerinterceptoradapter{ public boolean prehandle(httpservletrequest request, httpservletresponse response, object handler) throws exception { system.out.println("in interceptor"); return true; } public void posthandle( httpservletrequest request, httpservletresponse response, object handler, modelandview modelandview) throws exception { system.out.println("in post handler"); } public void aftercompletion( httpservletrequest request, httpservletresponse response, object handler, exception ex) throws exception { system.out.println("after completion"); } }
and registering interceptor below,
@configuration @enablewebmvc @componentscan(basepackages="demo.mycustom") public class myinterceptorconfig extends webmvcconfigureradapter{ @autowired mycustominterceptor obj; @override public void addinterceptors(interceptorregistry registry) { registry.addinterceptor(obj); } }
now challenge here is,
when try login "localhost:8096/myapp/#/login", returning me 404 page not found. being observed when add interceptor configuration. although think needed have tell application interceptor want register.
what can done here?
observations :
when debug , see inside prehandle interesting point "handler" parameter giving me org.springframework.boot.autoconfigure.web.basicerrorcontroller.errorhtml
when use application (without interceptor) getting org.springframework.web.servlet.mvc.parameterizableviewcontroller@1bff7859
this diverted mind have addviewcontrollers inside interceptor configuration. have no idea how add them , add them. tried adding view controller "/" , "/login" view names accordingly. somehow doesn't work.
could enlighten me in this. have gone through links in stackoverflow on , not find anything, may not relate requirement.
the problem solved removing enablewebmvc annotation. din't knew ;)
i missed below piece while reading,
i never wanted complete control on spring mvc. wanted implement interceptor.
Comments
Post a Comment