Update MvcUriComponentsBuilder to use DispServlet WAC
Issue: SPR-8826
This commit is contained in:
parent
cf5db8362b
commit
14b9931ee3
|
|
@ -40,6 +40,8 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||||
import org.springframework.web.method.annotation.RequestParamMethodArgumentResolver;
|
import org.springframework.web.method.annotation.RequestParamMethodArgumentResolver;
|
||||||
import org.springframework.web.method.support.CompositeUriComponentsContributor;
|
import org.springframework.web.method.support.CompositeUriComponentsContributor;
|
||||||
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
|
import org.springframework.web.servlet.support.RequestContextUtils;
|
||||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||||
import org.springframework.web.util.UriComponents;
|
import org.springframework.web.util.UriComponents;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
@ -297,10 +299,10 @@ public class MvcUriComponentsBuilder extends UriComponentsBuilder {
|
||||||
logger.debug("Request bound to current thread is not an HttpServletRequest");
|
logger.debug("Request bound to current thread is not an HttpServletRequest");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ServletContext servletContext = request.getServletContext();
|
WebApplicationContext wac = (WebApplicationContext) request.getAttribute(
|
||||||
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
|
DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
|
||||||
if (wac == null) {
|
if (wac == null) {
|
||||||
logger.debug("No WebApplicationContext found: no ContextLoaderListener registered?");
|
logger.debug("No WebApplicationContext found: not in a DispatcherServlet request?");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue