한 프로젝트의 spring-config.xml을 다른 프로젝트의 spring-config.xml로 가져 오는 방법은 무엇입니까?
이름 simple-core-impl
과 simple-core-web
.
두 프로젝트는 spring based
모두 상위 프로젝트 이름 simple-core
입니다.
나는이 simple-impl-config.xml
에 simple-core-impl
프로젝트 simple-web-config.xml
에 simple-impl-config.xml
.
클래스가있는 bean이 있습니다 : simple service
"hello World"메시지를 반환하는 하나의 메서드가 있습니다.
나는를 가져올 simple-impl-config.xml
에 simple-web-config.xml
콩이에 내 컨트롤러로 사용할 수 있도록 simple-core-web
프로젝트.
simple-core-web
프로젝트에는 프로젝트의 항아리가 simple-core-impl
있습니다.
spring-config.xml
한 프로젝트를 spring-config.xml
다른 프로젝트 로 가져올 수있는 방법을 알려주세요. 그러면 처음의 모든 빈을 가져 오기만 하면 다른 프로젝트에서 사용할 수 있습니다.
모든 콩을 다시 쓰고 싶지 않습니다.
<import resource="classpath:spring-config.xml" />
참고:
- XML 기반 구성 메타 데이터 작성
- 리소스 (여기에서
classpath:
부품 설명)
Sean의 대답의 작은 변형 :
<import resource="classpath*:spring-config.xml" />
별표를 사용하여 클래스 경로의 모든 위치에서 'spring-config.xml'파일을 검색합니다.
또 다른 참조 : 여러 프로젝트에서 Spring 구성 나누기
어떤 이유로 Ricardo가 제안한 가져 오기가 저에게 효과적이지 않았습니다. 다음 진술로 작업했습니다.
<import resource="classpath*:/spring-config.xml" />
다음은 주석 기반 예입니다.
@SpringBootApplication
@ImportResource({"classpath*:spring-config.xml"})
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
모듈 A에 모듈 B의 jar / war을 추가하고 새 스프링 모듈 파일에 클래스 경로를 추가해야합니다. 이 줄을 추가하십시오
spring-moduleA.xml-리소스 폴더 아래의 모듈 A에있는 파일입니다. 이 행을 추가하여 모듈 A에서 모듈 B로 모든 Bean 정의를 가져옵니다.
모듈 B / spring-moduleB.xml
import resource="classpath:spring-moduleA.xml"/>
<bean id="helloBeanB" class="basic.HelloWorldB">
<property name="name" value="BMVNPrj" />
</bean>
<import resource="classpath*:spring-config.xml" />
이것은 클래스 경로 구성에 가장 적합한 것입니다. 특히 클래스 경로에있는 다른 프로젝트에서 .xml 파일을 검색 할 때.
'Development Tip' 카테고리의 다른 글
JQuery Ajax Post 결과 500 내부 서버 오류 발생 (0) | 2020.10.20 |
---|---|
Cordova : JDK 1.8 이상에 대한 요구 사항 확인 실패 (0) | 2020.10.20 |
Android Studio-디버그 대신 릴리스 APK 배포 (0) | 2020.10.20 |
UIPickerView가로드 된 후 행 선택 (0) | 2020.10.20 |
Virtualenv 및 소스 버전 제어 (0) | 2020.10.19 |