springboot的application.properties配置文件的配置项读取

  1. package Solin.controller;  
  2.   
  3. import org.springframework.beans.factory.annotation.Autowired;  
  4. import org.springframework.beans.factory.annotation.Value;  
  5. import org.springframework.core.env.Environment;  
  6. import org.springframework.web.bind.annotation.RequestMapping;  
  7. import org.springframework.web.bind.annotation.RestController;  
  8.   
  9. @RestController  
  10. public class WebController {  
  11.     @Autowired  
  12.     private Environment env;  

  13.     //test.msg就是配置键
  14.     @RequestMapping("/index")   
  15.     public String index2(){  
  16.         return env.getProperty("test.msg");  
  17.     }  

猜你喜欢

转载自blog.csdn.net/csdnchen666666/article/details/79583791