o.s.io.core.Resource 에 와일드카드를 붙이고 싶을 때

soomin·2021년 8월 18일
0

출처: StackOverflow


o.s.c.Resource 구현 클래스는 wildcard 를 인식하지 못함

1.PathMatchingResourcePatternResolver


  • PathMatchingResourcePatternResolver
    • 해당 클래스는 #getResources() 함수로 패턴이 포함된 경로를 받아 Resource 구현체 배열을 리턴

PathMatchingResourcePatternResolver는 Resource 구현체를 Prefix 로 구분하므로 Prefix를 반드시 기입한다.
즉, 생성할 Resource 인터페이스 구현체를 Prefix 로 결정한다.


  • 접두사를 기입했으므로 ClassPathResource 클래스로 생성
// 접두사 기입
public static final String MAPPER_LOCATIONS_PATH = "classpath:mybatis/sql/**/*.xml";

// 생성
PathMatchingResourcePatternResolver resource = new PathMatchingResourcePatternResolver();
// #getResource() 함수에 패턴이 들어간 리소스 경로를 인자로 전달
resource.getResources(MAPPER_LOCATIONS_PATH);// class path resource [mybatis/sql/**/*.xml]
profile
블로그 유목민

0개의 댓글