Choi의 고유결계

Spring - XML파일에 JAVA파일 포함시켜 적용하기 본문

Spring

Spring - XML파일에 JAVA파일 포함시켜 적용하기

믿을수없는맛 2019. 3. 4. 22:50
반응형

XML파일에 JAVA파일 포함시켜 적용하기

오늘 배워 볼것은 XML 파일을 하나의 XML파일에 적용하는 방법입니다.

mongoContext.java


@Configuration
public class Application {

    @Bean
    public CustomerService customerService() {
        return new CustomerService();
    }

    @Bean
    public OrderService mongoService() {
        return new mongoService();
    }
}

root-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


</beans>

mongoContext.java 파일을 root-context.xmlimport 해보겠습니다.


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <context:annotation-config/>
    <bean class="mongoContext"/>

</beans>

한줄 추가로 xml 파일에 java로 작성한 설정파일을 포함시켰습니다.

<context:annotation-config/>
<bean class="mongoContext"/>

바로 이 스크립트 부분이 파일을 임포트하는 스크립트입니다.
context:annotation-config 를 먼저 쓰고,

기존과 같이 포함시킬 java 파일일 bean 태그로 생성해줍니다.


반응형
Comments