Home > AI > Backend > SpringBoot >

Environment getProperty

application.properties

hello.name = "value"

DemoApplication.java

@RestController
@SpringBootApplication
public class DemoApplication {
    @Autowired
    Environment env;

	public static void main(String[] args) {


        SpringApplication.run(DemoApplication.class, args);
	}

	@GetMapping("/hello")
    public String hello() {
	    return env.getProperty("hello.name");
    }

}

Leave a Reply