我正在尝试将所有属性文件加载到List中,但是看起来一切都无法正常进行。我正在关注:https://www.mkyong.com/spring-boot/spring-boot-configurationproperties-example/。我正在使用Spring Boot v2.2.2.RELEASE。
@Configuration
@PropertySource(value="classpath:endpoints.properties")
public class AppConfig {
@Value("#{'${endpoints}'.split(',')}")
private List<String> endpoints;
public List<String> getEndPoints() {
return endpoints;
}
//To resolve ${} in @Value
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
return new PropertySourcesPlaceholderConfigurer();
}
}
[当我在下面使用此功能时,出现异常。
@Autowired
private Environment env;
@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
if(endpoint instanceof MethodEndpoint) {
MethodEndpoint methodEndpoint = (MethodEndpoint)endpoint;
List<String> endpoints = Arrays.asList(env.getProperty("endpoints", String[].class));
return endpoints.contains(methodEndpoint.getMethod().getName());
}
return true;
}
编辑:
@Slf4j
@Component
public class DecisionInterceptor implements EndpointInterceptor {
@Value("#{'${endpoints}'.split(',')}")
private List<String> endpoints;
@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
if(endpoint instanceof MethodEndpoint) {
MethodEndpoint methodEndpoint = (MethodEndpoint)endpoint;
// List<String> endpoints = Arrays.asList(env.getProperty("edr.soap.endpoints", String[].class));
return endpoints.contains(methodEndpoint.getMethod().getName());
}
return true;
}
@Override
public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception {
return true;
}
@Override
public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
return true;
}
@Override
public void afterCompletion(MessageContext messageContext, Object endpoint, Exception ex) throws Exception {
log.debug("DecisionInterceptor - afterCompletion executed ...");
}
}
总结评论意见。看起来这是与this类似的问题。并且应该检查在DecisionInterceptor
中如何构造Configuration
。