title: How to set background url for css files in thymeleaf?
body: <p>I have a thymeleaf template where I don't have CSS files imported and wanted to declare style attribute for the body element with <code>background-image: url{/image.jpg}</code> property with relative image URL. I wanted to load the URL without including the application context name(<code>/myapp/</code>) it. It is similar to the problem over <a href="http://forum.thymeleaf.org/background-url-in-a-css-file-td4024757.html" rel="nofollow noreferrer">here</a>, except it din't work for me.</p>
  
  <p>CSS:</p>
  
  <pre><code>&lt;style&gt;
  body {
      background: url(../img/Background.jpg)
                  no-repeat center center fixed;
      background-size: cover;
  }
  &lt;/style&gt;
  </code></pre>
  
  <p>But the above CSS doesn't work and it accessed the image at </p>
  
  <pre><code>http://localhost/img/Background.jpg. 
  </code></pre>
  
  <p>So, I had to give the value as <code>url(/myapp/img/Background.jpg)</code> for the image to load properly.</p>
  
  <p>I have the <code>mvc:resources</code> configuration properly set in <code>spring-context.xml</code> for <code>/img/</code> request to load properly and it works in other places. </p>
  
  <p><strong>spring-context.xml</strong></p>
  
  <pre><code>&lt;mvc:resources mapping="img/**" location="/WEB-INF/img/" /&gt;
  </code></pre>
  
  <p>So how to load the background url image css value dynamically using thymeleaf's relative url?</p>