복붙노트

[SPRING] 스프링 XML 파일을 스프링 @Configuration 클래스로 변환

SPRING

스프링 XML 파일을 스프링 @Configuration 클래스로 변환

Understanding Spring @Autowired usage 스프링 배선의 다른 옵션 인 @Configuration 클래스에 대한 완벽한 지식 기반을 만들고 싶었습니다.

다음과 같이 봄 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-3.0.xsd">

  <import resource="another-application-context.xml"/>

  <bean id="someBean" class="stack.overflow.spring.configuration.SomeClassImpl">
    <constructor-arg value="${some.interesting.property}" />
  </bean>

  <bean id="anotherBean" class="stack.overflow.spring.configuration.AnotherClassImpl">
    <constructor-arg ref="someBean"/>
    <constructor-arg ref="beanFromSomewhereElse"/>
  </bean>
</beans>

대신 @Configuration을 어떻게 사용할 수 있습니까? 코드 자체에 영향을 미칩니 까?

해결법

  1. ==============================

    1.(면책 -이 답변은 내 블로그 게시물을 기반으로합니다)

    (면책 -이 답변은 내 블로그 게시물을 기반으로합니다)

    몇 단계에서 xml을 @Configuration으로 마이그레이션 할 수 있습니다.

    기본적으로 XML을 사용하는 것보다 빈을 선언하는이 방법은 내가 보는 몇 가지 장점 때문에 찾을 수 있습니다.

    단점은 내가보기에는 그다지 많지 않지만 생각할 수있는 몇 가지가 있습니다.

    결론 : 애플리케이션 컨텍스트에서 XML, @Configuration 및 주석을 결합하는 것은 완벽합니다. Spring은 bean이 선언 된 메소드를 신경 쓰지 않는다.

  2. from https://stackoverflow.com/questions/24014919/converting-spring-xml-file-to-spring-configuration-class by cc-by-sa and MIT license