是否可以像C中的app.config那样在java中转换.properties文件#
我在我们的项目中有带有调试设置的是否可以像C中的app.config那样在java中转换.properties文件#,java,c#,config-transformation,Java,C#,Config Transformation,我在我们的项目中有带有调试设置的debug.properties文件。此文件位于repo中,每个teamate在调试之前都应该对此文件进行更改 在C#中进行类似生成的xml转换之前,是否可以基于一些debug.template.properties文件修改此文件?您可以使用库和以下代码: private ConfigurationProvider configureProvider() { ClassLoader classLoader = getClass().getClassLoad
debug.properties
文件。此文件位于repo中,每个teamate在调试之前都应该对此文件进行更改
在C#中进行类似生成的xml转换之前,是否可以基于一些debug.template.properties
文件修改此文件?您可以使用库和以下代码:
private ConfigurationProvider configureProvider() {
ClassLoader classLoader = getClass().getClassLoader();
String envPath = classLoader.getResource("properties").getPath();
Path localPropertiesFilePath = Paths.get(envPath, "local.properties");
Path basePropertiesFilePath = Paths.get(envPath, "base.properties");
if (!Files.exists(localPropertiesFilePath)) {
try {
Files.createFile(localPropertiesFilePath);
}
catch (IOException exception) {
exception.printStackTrace();
}
}
ConfigFilesProvider localConfigFilesProvider =
() -> Collections.singletonList(localPropertiesFilePath);
ConfigFilesProvider baseConfigFilesProvider =
() -> Collections.singletonList(basePropertiesFilePath);
ConfigurationSource local = new FilesConfigurationSource(localConfigFilesProvider);
ConfigurationSource base = new FilesConfigurationSource(baseConfigFilesProvider);
// If you have 'some' property in base and local files - it takes from local
ConfigurationSource mergedSource = new MergeConfigurationSource(base, local);
Environment environment = new ImmutableEnvironment(envPath);
return new ConfigurationProviderBuilder()
.withConfigurationSource(mergedSource)
.withEnvironment(environment)
.build();
}