title: Spring: how pass values to constructor from properties file
body: <p>I have a <code>MongoService</code> class as  </p>
  
  <pre><code>public class MongoService {
  
      private final Mongo mongo;
      private final String database;
      private static final Logger LOGGER = LoggerFactory.getLogger(MongoService.class);
  
      public MongoService(@Nonnull final String host, final int port, @Nonnull final String db) throws UnknownHostException {
          mongo = new Mongo(host, port);
          database = db;
      }
  
      public void putDocument(@Nonnull final DBObject document) {
          LOGGER.info("inserting document - " + document.toString());
          mongo.getDB(database).getCollection(getCollectionName(document)).insert(document, WriteConcern.SAFE);
      }
  
      public void putDocuments(@Nonnull final List&lt;DBObject&gt; documents) {
          for (final DBObject document : documents) {
              putDocument(document);
          }
      }
  
  }
  </code></pre>
  
  <p>I want to inject the value of <code>host, port, db</code> into <strong>constructor</strong> from a external properties file<br>
  <strong>/storage/local.properties</strong>  </p>
  
  <pre><code>### === MongoDB interaction === ###
  host=127.0.0.1
  port=27017
  database=contract  
  </code></pre>
  
  <p>My Spring wireup file looks as follows<br>
  <strong>wireup.xml</strong>  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"&gt;
  
      &lt;util:properties id="mongoProperties" location="file:///storage//local.properties" /&gt;
  
      &lt;bean id="mongoService" class="com.business.persist.MongoService"&gt;
          // TODO
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Question</strong>  </p>
  
  <p>How can I pass the value of <code>host, port, db</code> from <code>local.properties</code> file and pass it to the following constructor?   </p>
  
  <pre><code>public MongoService(@Nonnull final String host, final int port, @Nonnull final String db) throws UnknownHostException {
          mongo = new Mongo(host, port);
          database = db;
      }
  </code></pre>