spring.application.name=limits-service //name of application
package com.lidihuo.microservices.limitsservice; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import com.lidihuo.microservices.limitsservice.bean.LimitConfiguration; @RestController public class LimitsConfigurationController { @GetMapping("/limits") public LimitConfiguration retriveLimitsFromConfigurations() { return new LimitConfiguration(1000, 1); } }
package com.lidihuo.microservices.limitsservice.bean; public class LimitConfiguration { private int maximum; private int minimum; //no-argument constructor protected LimitConfiguration() { } //generating getters public int getMaximum() { return maximum; } public int getMinimum() { return minimum; } //genetrating constructor using fields public LimitConfiguration(int maximum, int minimum) { super(); this.maximum = maximum; this.minimum = minimum; } }
{ maximum: 1000, minimum: 1 }
limits-service.minimum=99 limits-service.maximum=9999
package com.lidihuo.microservices.limitsservice; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @Component @ConfigurationProperties("limits-service") public class Configuration { private int maximum; private int minimum; public void setMaximum(int maximum) { this.maximum = maximum;} public void setMinimum(int minimum) { this.minimum = minimum; } public int getMaximum() { return maximum; } public int getMinimum() { return minimum; } }
package com.lidihuo.microservices.limitsservice; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import com.lidihuo.microservices.limitsservice.bean.LimitConfiguration; @RestController public class LimitsConfigurationController { @Autowired private Configuration configuration; @GetMapping("/limits") public LimitConfiguration retriveLimitsFromConfigurations() { //getting values from the properties file return new LimitConfiguration(configuration.getMaximum(), configuration.getMinimum()); } }
{ maximum: 999, minimum: 99 }