spring - How to get mvc RequestMappingHandlerMapping reference in a service? -
my application need aware mapped url's since username, or other resource types dynamically mapped.
even been able current mapping, can on controller:
@autowired requestmappinghandlermapping handlermapping; public void showhandlersmapping() { map<requestmappinginfo,handlermethod> map = handlermapping.gethandlermethods(); iterator<?> = map.entryset().iterator(); while (it.hasnext()) { map.entry pairs = (map.entry)it.next(); system.out.println(pairs.getkey() + " = " + pairs.getvalue()); } }
but have reference in root-context
other bean query against it.
how accomplish once mvc context gets loaded after root-context?
my solution (till now):
added @postconstruct controller call apiservice.registerhandlersmapping(handlermapping);
i'm not sure drawbacks approach appreciate advice.
i can't think of different solution other approach have mentioned of injecting in mappings web layer services layer. there few design issues here, have noted - services layer being dependent on web layer, , can think of few ways mitigate this:
extract essence of require handlermappings (say simple
map<string, string>
, inject alone services tier, way atleast dependencies reduced little.move specific services web tier, way web related dependencies remain in web tier.
Comments
Post a Comment