- package Solin.controller;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.core.env.Environment;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- @RestController
- public class WebController {
- @Autowired
- private Environment env;
-
- //test.msg就是配置键
- @RequestMapping("/index")
- public String index2(){
- return env.getProperty("test.msg");
- }
- }
springboot的application.properties配置文件的配置项读取
最新推荐文章于 2024-10-16 21:35:31 发布
本文介绍了一个使用Spring Boot框架的简单示例,展示了如何通过@RestController注解创建一个Web控制器,并利用Spring的Environment接口从配置文件中读取属性。具体来说,该示例中的WebController类使用了@RequestMapping注解来映射HTTP请求到特定的方法,通过@Autowired注解注入了Environment实例,从而能够获取名为'test.msg'的配置项。
1276

被折叠的 条评论
为什么被折叠?



