0

问题

我正在尝试设置ignore-unresolvable="true".

我从如何在春季定义非强制性属性的问题中找到了答案https://stackoverflow.com/a/11773267/1688441 ?.

他们展示的例子是:

<context:property-placeholder ignore-unresolvable="true" ... />

但是,在我继承的项目中,我们有一个名为的项目文件project.xml,其中包含Resource带有Context标签的定义。

<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource />
<ResourceLink />
<Resource />
</Context>

注意:资源已被删除

当我编辑Context标签以添加ignore-resolvable所有内容时,甚至我的DataSource资源都没有被读取。有人有想法么?

我尝试了以下方法:

<Context:property-placeholder ignore-unresolvable="true">

可能相关:

spring PropertyPlaceholderConfigurer 和 context:property-placeholder

4

1 回答 1

1

事实证明,在特定项目中,使用的是基于类的配置而不是 XML。我setIgnoreUnresolvablePlaceholders(false)在返回的方法中找到了以下类PropertySourcesPlaceholderConfigurer

@Configuration
@ComponentScan
@EnableWebMvc
@EnableAsync
@EnableScheduling
@PropertySource(value = {"classpath:appProp.properties"})
@Import({ExternalizeConfiguration.class, AppApplication.class,
        AppPersistenceApplication.class, ConnectBoIntegrationApplication.class})
public class AppWebApplication extends WebMvcConfigurerAdapter {

...Other Code...

/**
     * Bean required for Value annotation
     */
    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        PropertySourcesPlaceholderConfigurer test = new PropertySourcesPlaceholderConfigurer();
        test.setIgnoreUnresolvablePlaceholders(false);
        return test;
    }

}

所以我的理解是,将此方法注释为会导致该方法在自动连接@Bean类型的对象时执行。PropertySourcesPlaceholderConfigurer通过这种方式,我们控制使用哪个实例以及在其上设置哪些参数。

于 2016-08-04T08:42:11.400 回答