예제 4-69 XML 구성에서 구성 클래스 빈 가져오기 테스트([[java-config-message-provider]] JavaConfigExampleThree.java)
package com.apress.prospring5.ch4; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.apress.prospring5.ch2.decoupled.MessageRenderer; public class JavaConfigExampleThree { public static void main(String... args) { ApplicationContext ctx = new ClassPathXmlApplicationContext ("classpath:spring/app-context-xml-02.xml"); MessageRenderer renderer = ctx.getBean("messageRenderer", MessageRenderer.class); renderer.render(); } }
이 코드를 실행하면 이전 예제와 동일한 실행 결과가 출력됩니다.
Note 자바 구성 클래스에서 애플리케이션 인프라 서비스도 정의할 수 있습니다. 예를 들어 @EnableTransac tionManagement는 스프링의 트랜잭션 관리 기능을 사용할 것임을 정의하며 이는 9장에서 더 살펴보겠습니다. 또한, @EnableWebSecurity와 @EnableGlobalMethodSecurity는 스프링 보안 컨텍스트를 활성화하는 데 사용되며 16장에서 더 자세히 알아보겠습니다.