title: How to send a messages.properties key to an exception being thrown in a controller?
body: <p>I am trying to implement custom messages with a different language in my application built with Spring Boot 2. So far I have implemented it for entities' fields using keys set in <code>messages_br.properties</code>. Now, I'm trying the same with exception messages thrown in controllers, but I don't understand how to do it. Examples show too much of things I believe is not what I need.</p>
  
  <p>To configure the file, this is in my <code>Application.java</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Bean
  public MessageSource messageSource() {
      ReloadableResourceBundleMessageSource bundleMessageSource = new ReloadableResourceBundleMessageSource();
      bundleMessageSource.setBasename("classpath:messages_br");
      bundleMessageSource.setDefaultEncoding("UTF-8");
  
      return bundleMessageSource;
  }
  
  @Bean
  public LocalValidatorFactoryBean getValidator() {
      LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
      bean.setValidationMessageSource(messageSource());
  
      return bean;
  }
  </code></pre>
  
  <p>In the annotations above each field, I can specify something like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>@NotEmpty(message = "{beneficiary.name.notEmpty}")
  private String name;
  </code></pre>
  
  <p>But the same format in a thrown exception prints that only:</p>
  
  <pre class="lang-java prettyprint-override"><code>throw new InsufficientBalanceException("${user.balance.insufficientBalance}");
  </code></pre>
  
  <p>I'm almost sure that when learning how to implement exceptions I saw a similar example but now I cannot find it anymore nor I remember how it is done.</p>