title: Spring: Use application property inside an autowired constructor that instantiate a final field
body: <p>I've created the <a href="https://stackoverflow.com/help/mcve">MCVE</a> below. The service should get a message and replace the vowels with a predefined <code>ugly.char</code> coming from <code>application.properties</code>. </p>
  
  <p><strong>application.properties:</strong></p>
  
  <pre><code>ugly.char=x
  </code></pre>
  
  <p><strong>UglifyService.java:</strong></p>
  
  <pre><code>public interface UglifyService {
      String uglifyMessage(String message);
  }
  </code></pre>
  
  <p><strong>UglifyServiceImpl.java:</strong></p>
  
  <pre><code>@Service
  public class UglifyServiceImpl implements UglifyService {
  
      @Value("${ugly.char}")
      private char uglyCharFromAppProp;
  
      private final char uglyChar;
  
      @Autowired
      public UglifyServiceImpl() {
          this.uglyChar = uglyCharFromAppProp;
      }
  
      @Override
      public String uglifyMessage(String message) {
          return message.replaceAll("[aeiouAEIOU]", String.valueOf(uglyChar));
      }
  }
  </code></pre>
  
  <p><strong>UglyCharController.java:</strong></p>
  
  <pre><code>@Controller
  public class UglyCharController {
  
      private final UglifyService uglifyService;
  
      @Autowired
      public UglyCharController(UglifyService uglifyService) {
          this.uglifyService = uglifyService;
      }
  
      @Value("${ugly.char}")
      private char uglyChar;
  
      @RequestMapping("/")
      @ResponseBody
      public String index() {
          return "Usage: http://localhost:8080/some-message";
      }
  
      @GetMapping("/{message:.+}")
      @ResponseBody
      public String uglifyMessage(@PathVariable String message) {
          String uglyMessage = uglifyService.uglifyMessage(message);
          return "The ugly char is: '"+ uglyChar +"'." +
                  "&lt;br&gt;The uglifyed message is: "+ uglyMessage;
      }
  }
  </code></pre>
  
  <p><strong>Application.java:</strong></p>
  
  <pre><code>@SpringBootApplication
  public class Application {
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <hr>
  
  <p>The problem is that, instead of replacing the vowels, the service is just removing them.</p>
  
  <p>When requesting <code>localhost:8080/mymessage</code> the response should be <code>mymxssxgx</code>, but I am getting <code>mymssg</code>.</p>
  
  <p><strong>My questions are:</strong></p>
  
  <ol>
  <li>Why the service is not working as expected?</li>
  <li>What would be the right way to make it work, considering that I would like the <code>uglyChar</code> to be final inside the singleton service and to come from <code>application.properties</code>?</li>
  </ol>
  
  <p><strong>Note:</strong> The service starts to work if I replace <code>String.valueOf(uglyChar)</code> with <code>String.valueOf(uglyCharFromAppProp)</code>, but <code>uglyChar</code> would not be final, as I would like it to be.</p>