Spring Cloud 2.3.1 指定配置文件路径

1.开发步骤:

1. 修改启动类

指定配置文件路径:spring.config.location=classpath:/test-folder/my-config.properties

	public static void main(String[] args) {
		ConfigurableApplicationContext context = new SpringApplicationBuilder(
				TestDefaultFile.class)
				.properties(
						"spring.config.location=classpath:/test-folder/my-config.properties")
				.run(args);
		// 输出变量
		System.out.println(context.getEnvironment().getProperty("jdbc.user"));
	}

2. 启动Spring boot 验证

输出了 jdbc.user = e

2.源码:

项目源码路径:02/boot-config-file

Spring Cloud 全部源码 百度云:https://pan.baidu.com/s/1pTQC-MXDAoHqv0BU79uyaw

猜你喜欢

转载自blog.csdn.net/ladymorgana/article/details/81327475