Skip to content

Commit 14b9931

Browse files
committed
Update MvcUriComponentsBuilder to use DispServlet WAC
Issue: SPR-8826
1 parent cf5db83 commit 14b9931

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import org.springframework.web.context.support.WebApplicationContextUtils;
4141
import org.springframework.web.method.annotation.RequestParamMethodArgumentResolver;
4242
import org.springframework.web.method.support.CompositeUriComponentsContributor;
43+
import org.springframework.web.servlet.DispatcherServlet;
44+
import org.springframework.web.servlet.support.RequestContextUtils;
4345
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
4446
import org.springframework.web.util.UriComponents;
4547
import org.springframework.web.util.UriComponentsBuilder;
@@ -297,10 +299,10 @@ protected static CompositeUriComponentsContributor getConfiguredUriComponentsCon
297299
logger.debug("Request bound to current thread is not an HttpServletRequest");
298300
return null;
299301
}
300-
ServletContext servletContext = request.getServletContext();
301-
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
302+
WebApplicationContext wac = (WebApplicationContext) request.getAttribute(
303+
DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
302304
if (wac == null) {
303-
logger.debug("No WebApplicationContext found: no ContextLoaderListener registered?");
305+
logger.debug("No WebApplicationContext found: not in a DispatcherServlet request?");
304306
return null;
305307
}
306308
try {

0 commit comments

Comments
 (0)