这里有两个问题。
1)EncryptedPropertySourceLoader的加载需要高于标准PropertiesPropertySourceLoader的加载。这可以通过实现PriorityOrder接口来实现,如下所示:
public class EncryptedPropertySourceLoader implements PropertySourceLoader, PriorityOrdered{ private final StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); public EncryptedPropertySourceLoader() { this.encryptor.setPassword("password"); //TODO: this could be taken from an environment variable } @Override public String[] getFileExtensions() { return new String[]{"properties"}; } @Override public PropertySource<?> load(final String name, final Resource resource, final String profile) throws IOException { if (profile == null) { //load the properties final Properties props = PropertiesLoaderUtils.loadProperties(resource); if (!props.isEmpty()) { //create the encryptable properties property source return new EncryptablePropertiesPropertySource(name, props, this.encryptor); } } return null; } @Override public int getOrder() { return HIGHEST_PRECEDENCE; }}使用将从订单中
org.springframework.core.io.support.SpringFactoriesLoader加载结果的类。意味着应首先返回此类,并将负责为*
.proerpties文件提供PropertySourceLoader实现。
org.springframework.boot.env.PropertySourceLoader``meta-INF/spring.factories``org.springframework.core.OrderComparator
2)第二个问题是可执行JAR / WAR的类加载问题,这似乎是由Windows上的Spring
Boot版本1.1.2.RELEASE中的错误引起的。降至版本1.1.1.RELEASE或版本1.1.3RELEASE解决了在maven外部运行时类和属性文件未加载的各种问题。



