title: Spring Boot - how do I get the base url of a request
body: <p>I'm running a spring boot and a few of my domain services need to know the domain name.  </p>
  
  <p>I know that I could capture it at the application layer in the controller method like this:</p>
  
  <pre><code> @RequestMapping(value="/myMapping",method = RequestMethod.POST)
   public ModelandView myAction(HttpServletRequest request) {
  
   }
  </code></pre>
  
  <p>OR that, if I were running a traditional web application with a war that I could configure a listener like this:</p>
  
  <pre><code>&lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>And access it like this:</p>
  
  <pre><code>((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest()
  </code></pre>
  
  <p>But I do not want to pass around arguments like I would if I captured it at the controller, and I am not running a war with a web.xml.  </p>
  
  <p>How can I have my cake and eat it too?</p>