Cor*_*chi 5 spring spring-boot
我正在尝试获取财产的价值
hello.world=Hello World
Run Code Online (Sandbox Code Playgroud)
在 MainApp 类中
@SpringBootApplication
public class MainApp {
public static void main(String[] args) {
SpringApplication.run(MainApp.class, args);
}
Run Code Online (Sandbox Code Playgroud)
这不是它的主要方法。
@Value("${hello.world}")
public static String helloWorld;
Run Code Online (Sandbox Code Playgroud)
也许它可以加载
Properties prop = new Properties();
// load a properties file
prop.load(new FileInputStream(filePath));
Run Code Online (Sandbox Code Playgroud)
在 SpringApplication.run 之前的 SpringBoot 的 main 方法中,有没有其他更好的方法来使用 Spring 获取属性
ConfigurableApplicationContext ctx =
SpringApplication.run(MainApp.class, args);
String str = ctx.getEnvironment().getProperty("some.prop");
System.out.println("=>>>> " + str);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9430 次 |
| 最近记录: |