首页 > 其他分享 >spring boot——读取应用配置——方式二——@Value

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

时间:2023-01-01 18:33:31浏览次数:35  
标签:spring boot springframework Value testValue org import annotation

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

读取数据并显示:

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;
    }
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

标签:spring,boot,springframework,Value,testValue,org,import,annotation
From: https://www.cnblogs.com/xiaobaibailongma/p/17018392.html

相关文章