使用spring boot版本1.2.3(也测试了1.2.5),我正在遵循创建Spring Boot中自定义Jasypt PropertySource 和 Spring Boot & Jasypt简化:保持敏感属性加密,使用自定义PropertySourceLoader使用jsypt库。我的源加载器类在api.jar中,并且这个jar文件包含在myapplication.war文件中。这个war被部署在tomcat中。
似乎在应用程序启动时,spring没有加载EncryptedPropertySourceLoader
。有人可以帮忙吗?
以下是我的项目结构和相关代码。
Project - api.jar
| src
| | main
| | java
| | EncryptedPropertySourceLoader.java
| | resources
| | META-INF
| | spring.factories
api.jar是使用api.jar!META-INF/spring.factories
构建的。
package com.test.boot.env;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.env.PropertySourceLoader;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
public class EncryptedPropertySourceLoader implements PropertySourceLoader, PriorityOrdered {
private static final Logger logger = LoggerFactory.getLogger(EncryptedPropertySourceLoader.class);
public EncryptedPropertySourceLoader() {
logger.error("\n\n\n***CREATING properties loader.\n\n\n");
}
@Override
public String[] getFileExtensions() {
return new String[] { "properties" };
}
@Override
public PropertySource<?> load(final String name, final Resource resource, final String profile) throws IOException {
logger.error("\n\n\n***Loading properties files.\n\n\n");
if (true) {
throw new RuntimeException("calling load"); \\intentional to identify the call
}
return null;
}
@Override
public int getOrder() {
return HIGHEST_PRECEDENCE;
}
}
spring.factories文件包含以下内容:
org.springframework.boot.env.PropertySourceLoader=\
com.test.boot.env.EncryptedPropertySourceLoader
我也尝试过不使用'\',但没有任何区别。
以下是myapplication.war
文件中spring.factories
的路径。
myapplication.war!WEB-INF/lib/api.jar!META-INF/spring.factories
根据我的理解,在启动时应该看到
RuntimeException
,但是我的应用程序成功启动了。有人可以帮忙找出我漏掉了什么吗?