• spring boot的基本配置——spring boot的全局配置文件——读取应用配置——@PropertySource注解+@Value注解——读取其它配置文件


     

     

     

     

    package com.test.controller;
    
    import com.test.controller.model.StudentProperties;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.PropertySource;
    import org.springframework.core.env.Environment;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    @PropertySource({"test.properties","ok.properties"})
    public class StartMainController
    {
        @Value("${my.msg}")
        private String mymsg;
    
        @Value("${your.msg}")
        private String yourmsg;
    
        @Autowired
        StudentProperties studentProperties;
    
    
    
        @Autowired
        private Environment ev;
    
        @Value("key_test_001")
        private  String as;
    
        @RequestMapping("/12")
        @ResponseBody
        public String home12()
        {
            return "hello---12";
        }
    
    
        @RequestMapping("/123")
        @ResponseBody
        public String home123()
        {
            return "hello---123";
        }
    
        @RequestMapping("/1234")
        @ResponseBody
        public String home1234()
        {
            return ev.getProperty("key_test");
        }
    
        @RequestMapping("/12345")
        @ResponseBody
        public String home12345()
        {
            return as;
        }
    
        @RequestMapping("/123456")
        @ResponseBody
        public String home123456()
        {
            return studentProperties.getSname();
        }
    
        @RequestMapping("/1234567")
        @ResponseBody
        public String home1234567()
        {
            return mymsg+"   "+yourmsg;
        }
    
    }
    

      

  • 相关阅读:
    6月23号 java方法 什么是方法?
    6月21号 Java流程控制 练习
    6月21号 Java流程控制 break continue
    6月21号 Java流程控制 增强for
    6月19号 Java流程控制 循环结构for练习
    6月18号 Java流程控制 循环结构for
    qbot
    clion 2019.2
    raptor
    字符串练习
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/16272957.html
Copyright © 2020-2023  润新知