스프링 클래스 패스 접두사 차이
문서화 여기 가 말한다
이 특수 접두사는 주어진 이름과 일치하는 모든 클래스 경로 자원을 가져와야하며 (내부적으로 이는 기본적으로 ClassLoader.getResources (...) 호출을 통해 발생 함) 병합 된 후 최종 애플리케이션 컨텍스트 정의를 구성하도록 지정합니다.
누군가 이것을 설명 할 수 있습니까?
별표 classpath*:conf/appContext.xml
가 classpath:conf/appContext.xml
없는 것과 반대로 사용하는 것의 차이점은 무엇입니까?
간단한 정의
이는 classpath*:conf/appContext.xml
단순히 클래스 경로의 모든 jar에있는 폴더 아래의 모든 appContext.xml 파일이conf
하나의 큰 애플리케이션 컨텍스트로 선택되어 결합 됨을 의미합니다 .
대조적으로, 당신의 클래스 경로에서 발견 된 첫 번째 파일 만classpath:conf/appContext.xml
로드 합니다 .
classpath*:...
와일드 카드 구문을 사용하여 여러 빈 정의 파일에서 응용 프로그램 컨텍스트를 구축 할 때 주로 구문 유용합니다.
예를 들어,을 사용하여 컨텍스트를 구성 classpath*:appContext.xml
하면 클래스 경로 appContext.xml
에서 호출 된 모든 자원에 대해 클래스 경로가 스캔되고 모든 자원 의 Bean 정의가 단일 컨텍스트로 병합됩니다.
대조적으로, 클래스 경로에서 classpath:conf/appContext.xml
하나의 파일 만 호출 appContext.xml
됩니다. 둘 이상이 있으면 다른 것들은 무시됩니다.
클래스 경로 * : 그것은을 의미 자원의 목록 및 모든 부하 등의 파일이 클래스 경로에 제시 비어있을 수 목록 및 경우에 그러한 파일이 존재하지 않는 클래스 패스에 다음 응용 프로그램 예외를 throw하지 않습니다는 (단지 오류를 무시합니다).
클래스 경로 : 그것은을 의미 특정 자원 과 첫 번째로드 파일을 클래스 패스에 발견하고 그러한 파일을 클래스 패스에 존재하지 않는 경우는 예외가 발생합니다
java.io.FileNotFoundException: class path resource [conf/appContext.xml] cannot be opened because it does not exist
Spring의 소스 코드 :
public Resource[] getResources(String locationPattern) throws IOException {
Assert.notNull(locationPattern, "Location pattern must not be null");
//CLASSPATH_ALL_URL_PREFIX="classpath*:"
if (locationPattern.startsWith(CLASSPATH_ALL_URL_PREFIX)) {
// a class path resource (multiple resources for same name possible)
if (getPathMatcher().isPattern(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()))) {
// a class path resource pattern
return findPathMatchingResources(locationPattern);
}
else {
// all class path resources with the given name
return findAllClassPathResources(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()));
}
}
else {
// Only look for a pattern after a prefix here
// (to not get fooled by a pattern symbol in a strange prefix).
int prefixEnd = locationPattern.indexOf(":") + 1;
if (getPathMatcher().isPattern(locationPattern.substring(prefixEnd))) {
// a file pattern
return findPathMatchingResources(locationPattern);
}
else {
// a single resource with the given name
return new Resource[] {getResourceLoader().getResource(locationPattern)};
}
}
}
참고 URL : https://stackoverflow.com/questions/3294423/spring-classpath-prefix-difference
'programing tip' 카테고리의 다른 글
잡히지 않은 TypeError : 정의되지 않은 [중복]의 'msie'속성을 읽을 수 없습니다 (0) | 2020.06.23 |
---|---|
Entity Framework 용 데이터베이스를 다시 만드는 방법은 무엇입니까? (0) | 2020.06.23 |
여러 조건이있는 XPath (0) | 2020.06.23 |
GraphQL 및 마이크로 서비스 아키텍처 (0) | 2020.06.22 |
HTML에서 SVG 크기를 조정 하시겠습니까? (0) | 2020.06.22 |