Development Tip

한 프로젝트의 spring-config.xml을 다른 프로젝트의 spring-config.xml로 가져 오는 방법은 무엇입니까?

yourdevel 2020. 10. 20. 08:12
반응형

한 프로젝트의 spring-config.xml을 다른 프로젝트의 spring-config.xml로 가져 오는 방법은 무엇입니까?


이름 simple-core-implsimple-core-web.

두 프로젝트는 spring based모두 상위 프로젝트 이름 simple-core입니다.

나는이 simple-impl-config.xmlsimple-core-impl프로젝트 simple-web-config.xmlsimple-impl-config.xml.

클래스가있는 bean이 있습니다 : simple service"hello World"메시지를 반환하는 하나의 메서드가 있습니다.

나는를 가져올 simple-impl-config.xmlsimple-web-config.xml콩이에 내 컨트롤러로 사용할 수 있도록 simple-core-web프로젝트.

simple-core-web프로젝트에는 프로젝트의 항아리가 simple-core-impl있습니다.

spring-config.xml한 프로젝트를 spring-config.xml다른 프로젝트 가져올 수있는 방법을 알려주세요. 그러면 처음의 모든 빈을 가져 오기만 하면 다른 프로젝트에서 사용할 수 있습니다.

모든 콩을 다시 쓰고 싶지 않습니다.


<import resource="classpath:spring-config.xml" />

참고:


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 파일을 검색 할 때.

참고 URL : https://stackoverflow.com/questions/5113579/how-to-import-spring-config-xml-of-one-project-into-spring-config-xml-of-another

반응형