【问题标题】:Dynamic Input in spring春季动态输入
【发布时间】:2019-03-14 06:26:36
【问题描述】:

我是 spring 新手,我尝试使用 spring 开发小应用程序。正如我在春天学习的那样,使用 xml 文件为属性提供值。我想在 java 中给出运行时的值,如下所示。

public class Main {

public static void main(String[] args) {
    Scanner num = new Scanner(System.in);
    int number = num.nextInt(); //dynamic value 
    }
 }

我怎样才能在春天实现这一目标。尝试谷歌并找到。但无法得到解决方案。

【问题讨论】:

标签: java xml spring


【解决方案1】:

1) 请将所有查询放入属性文件
2 ) 给出属性文件位置

@Configuration
@PropertySource("classpath:PropertiesFilename.properties");

3 ) 使用@Value 注解注入属性

@Value( "${Property which is exists in properties file.}" )
private String yourVaraibleName;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 2017-10-06
    • 2020-09-02
    • 1970-01-01
    • 2011-11-13
    • 2017-09-11
    • 2015-04-18
    相关资源
    最近更新 更多