title: Use Spring @Value on non-component object
body: <p>I've had this issue that i didn't know how to resolve. I made my Restful API using Spring Boot, and i am implementing the DTO-Domain-Entity pattern, so on this particular case i have this controller's method</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  @ResponseBody
  public ResponseEntity&lt;UserResponseDTO&gt; createUser(@RequestBody UserRequestDTO data) {
      UserDomain user = this.mapper.map(data, UserDomain.class);
      UserDomain createdUser = this.service.createUser(user);
      UserResponseDTO createdUserDTO = this.mapper.map(createdUser, UserResponseDTO.class);
      return new ResponseEntity&lt;UserResponseDTO&gt;(createdUserDTO, HttpStatus.CREATED);
  }
  
  public class UserDomain {
  
      private Long id;
  
      private Date createdDate;
  
      private Date updatedDate;
  
      private String username;
  
      private String password;
  
      @Value("${default.user.enabled:true}") // I have default-values.properties being loaded in another configuration file
      private Boolean enabled;
  }
  </code></pre>
  
  <p>I am transforming UserRequestDTO object to UserDomain. As i understand, UserRequestDTO is a bean that is being injected. Then i am transforming this to UserDomain, the problem here is that UserDomain object is not a component, so enabled attribute will not take the default value. </p>
  
  <p>In the case i wouldn't want to handle UserDomain as a bean, how could i make spring to load default values (just enabled attribute in this case)?</p>
  
  <hr>
  
  <h2>EDIT</h2>
  
  <p>It's not the same answer, since my goal is get it done using @Value annotations.</p>
  
  <p>Anyways, Would it be a better way doing something like this instead Constantine suggested?</p>
  
  <pre><code>public class UserDomain {
  
      @Autowired
      private Environment environment;
  
      private Boolean enabled;
  
      UserDomain(){
           this.enabled = environment.getProperty("default.user.enabled");
           // and all the other ones
      }
  
  }
  </code></pre>