title: Spring boot get application properties per request mapping
body: <p>I try to get per request some parameters from my application properties.</p>
  
  <p>My ApplicationConfig-Class:</p>
  
  <pre><code>@Configuration
  @ConfigurationProperties("org.a.b")
  public class ApplicationConfig implements Serializable {
  
      private String name;
      private String ip;
  // GETTER AND SETTER
  </code></pre>
  
  <p>My application.properties:</p>
  
  <pre><code>org.a.b.name=huhu
  org.a.b.ip=x.x.x.x
  </code></pre>
  
  <p>I try different possibilies:</p>
  
  <pre><code>@RestController
  public class HelloController
  </code></pre>
  
  <p>First:</p>
  
  <pre><code>@Autowired
  private ApplicationConfig applicationConfig;
  
  @ResponseBody
  @GetMapping(value = "/", produces = "application/json")
  public ApplicationConfig index() {
      return applicationConfig;
  }
  </code></pre>
  
  <p>Exception:</p>
  
  <pre><code>{"timestamp":"2018-08-24T12:28:50.623+0000","status":500,"error":"Internal Server Error","message":"Type definition error: [simple type, class org.springframework.context.expression.StandardBeanExpressionResolver]; nested exception is com.fasterxml.jackson.datab
  ind.exc.InvalidDefinitionException: No serializer found for class org.springframework.context.expression.StandardBeanExpressionResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (
  through reference chain: hello.bootstrap.ApplicationConfig$$EnhancerBySpringCGLIB$$31a0e3d2[\"$$beanFactory\"]-&gt;org.springframework.beans.factory.support.DefaultListableBeanFactory[\"beanExpressionResolver\"])","path":"/"}
  </code></pre>
  
  <p>Second:</p>
  
  <pre><code>@ResponseBody
  @GetMapping(value = "/", produces = "application/json")
  public ApplicationConfig index() {
      return new ApplicationConfig();
  }
  // return nothing {"name": null, "ip": null}
  </code></pre>
  
  <p>Third:</p>
  
  <pre><code>@ResponseBody
  @GetMapping(value = "/", produces = "application/json")
  public String index() {
      return applicationConfig.getIp();
  }
  // return x.x.x.x
  </code></pre>
  
  <p>My pom.xml:</p>
  
  <pre><code>&lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.0.3.RELEASE&lt;/version&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-configuration-processor&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
  
      &lt;build&gt;
          &lt;sourceDirectory&gt;src/main/java&lt;/sourceDirectory&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;mainClass&gt;hello.ConfigServiceApplication&lt;/mainClass&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  </code></pre>
  
  <p>I want the Application properties as Object, something like:</p>
  
  <pre><code>{"name": "dev", "ip": "x.x.x.x"}
  </code></pre>