spring boot——读取应用配置——方式二——@Value

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

=========================================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

读取数据并显示:

package org.example.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class ValueReaderConfigController
{

    @Value("${test.environment}")
    private String msg;

    //  http://localhost:8080/testValue

    @RequestMapping("/testValue")
    public String testValue()
    {

        return "方法二:" + msg;
    }
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

===============================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2023-01-01 18:15  小白龙白龙马  阅读(72)  评论(0)    收藏  举报