title: How to escape SpEL dollar signs in Spring YAML configuration?
body: <p>In a Spring YAML configuration file, I need to have a parameter like</p>
  <pre><code>csv:
    file:
      pattern: /some/path/${app-name}.csv
  </code></pre>
  <p>where the <code>${app-name}</code> is dynamically replaced in run time by the Java code, and I do not want Spring to replace it at the startup.</p>
  <p>To achieve this, I need to escape the <code>$</code> character so Spring does not interpret it as <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions" rel="noreferrer">SpEL</a>.</p>
  <p>The following answers <strong>do not</strong> work in YAML:</p>
  <ul>
  <li><p><code>\$</code> <a href="https://stackoverflow.com/q/8271033/2886891">How to escape EL dollar signs?</a></p>
  </li>
  <li><p><code>#{'$'}</code> <a href="https://stackoverflow.com/q/13162346/2886891">Escape property reference in Spring property file</a></p>
  </li>
  <li><p><a href="https://stackoverflow.com/q/43493857/2886891">Could not read properties if it contains dollar symbol (${var})</a></p>
  </li>
  </ul>
  <p>I tried all the combinations, like</p>
  <pre><code>pattern: /some/path/\${app-name}.csv
  pattern: &quot;/some/path/\${app-name}.csv&quot;
  pattern: /some/path/#{'$'}{app-name}.csv
  pattern: &quot;/some/path/#{'$'}{app-name}.csv&quot;
  </code></pre>
  <p>and none of them produces the variable containing the requested string, <strong>with</strong> the dollar sign but <strong>without</strong> the escape characters.</p>
  <p>Please notice that it is <strong>YAML</strong> configuration. In YAML files, <code>#</code> is the line comment character, everything from this character on is ignored. And if I use <code>\#</code>, the <code>\</code> is then passed to the string.</p>
  <p>ADDED: There has been an <a href="https://github.com/spring-projects/spring-framework/issues/9628" rel="noreferrer">Spring project open issue 9628</a> open since 25.06.2008:</p>
  <blockquote>
  <p>There is presently no way to inject a ${...} expression that won't be picked up by PropertyPlaceholderConfigurer. Ideally we should be able to inject a string that contains ${...} for later use in its target bean without involvement from PropertyPlaceholderConfigurer.</p>
  </blockquote>