Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法从Spring Boot中的属性文件加载密钥,null为@Autowired_Java_Spring_Spring Boot - Fatal编程技术网

Java 无法从Spring Boot中的属性文件加载密钥,null为@Autowired

Java 无法从Spring Boot中的属性文件加载密钥,null为@Autowired,java,spring,spring-boot,Java,Spring,Spring Boot,我希望将所有属性文件加载到列表中,但看起来好像一切都不正常。我下面是:。我使用的是SpringBootV2.2.2.0版本 @Configuration @PropertySource(value="classpath:endpoints.properties") public class AppConfig { @Value("#{'${endpoints}'.split(',')}") private List<String> endpoints; pu

我希望将所有属性文件加载到列表中,但看起来好像一切都不正常。我下面是:。我使用的是SpringBootV2.2.2.0版本

@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();
    }
}
编辑:

@Slf4j
@组成部分
公共类DecisionInterceptor实现EndpointInterceptor{
@值(“#{${endpoints}.split(',')}”)
私有列表端点;
@凌驾
公共布尔HandlerRequest(MessageContext,对象端点)引发异常{
if(方法端点的端点实例){
MethodEndpoint MethodEndpoint=(MethodEndpoint)端点;
//List endpoints=Arrays.asList(env.getProperty(“edr.soap.endpoints”,String[].class));
返回endpoints.contains(methodEndpoint.getMethod().getName());
}
返回true;
}
@凌驾
公共布尔HandlerResponse(MessageContext MessageContext,对象端点)引发异常{
返回true;
}
@凌驾
公共布尔handleFault(MessageContext,对象端点)引发异常{
返回true;
}
@凌驾
公共void afterCompletion(MessageContext MessageContext,对象端点,异常ex)引发异常{
调试(“DecisionInterceptor-完成后执行…”);
}
}

总结评论中的回复。
看来这是一个类似的问题。并且应该检查
DecisionInterceptor
是如何在
配置中构造的

您得到了什么异常?@Environment是null您使用Environment env的类是什么类型的Bean?import org.springframework.core.env.Environment@PAA你看到这个问题了吗?看起来是同一个问题:
@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 ...");
    }

}