Properties和Resouces通配符加载

Spring Properties默认不支持通过通配符加载配置文件,如果需要,需要自己在@Configration文件中增加单独的配置代码:

@Bean
    public static PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholderConfigurer() throws IOException {
        PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
        ppc.setLocations(new PathMatchingResourcePatternResolver().getResources("classpath:abc/channel/**/*.properties"));
        return ppc;
    }

 

对于Resouces文件,是支持通配符的:

?(匹配单个字符),*(匹配除/外任意字符)、**/(匹配任意多个目录)

posted @ 2021-11-24 14:34  maimode  阅读(119)  评论(0)    收藏  举报