我正在使用Spring开发Core.And应用程序,这个应用程序将作为可执行的Core.And工作。
此应用程序具有配置文件,该配置文件将使用@PropertySource加载,当前将此路径设置为"class- path :“。
我将在不同的机器上安装这个可执行的jar。可执行的jar文件夹路径将有所不同。
我需要将这个projectconfig.properties放在jar文件之外,以便用户能够根据他的要求设置配置。,我该怎么做?
如何动态设置路径?
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
@PropertySource("classpath:com/org/abc/xyz/properties/projectconfig.properties")
public class ProjectConfig {
@Autowired
private Environment env;
public String getProperty(String propName) {
return env.getProperty(propName);
}
}提前谢谢你!
发布于 2017-09-12 04:09:18
我建议你使用@ConfigurationProperties。Spring Boot将从start文件夹或./config文件夹加载application.properties。请阅读spring引导开发指南中的外化配置章节。
https://stackoverflow.com/questions/46167686
复制相似问题