| <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"> <context:component-scan base-package="spring.di.ui, spring.di.entity"/> <bean id="exam" class="spring.di.entity.NewlecExam" p:kor="10" p:eng="10"/> </beans> |
위와 같은 xml 파일을 대신하는 설정파일을 java class로 만드는 방법에 대해 알아보자.
| @ComponentScan({"Spring.di.ui", "Spring.di.entity" }) // 위 코드에서의 component-scan을 의미함. @Configuration // 설정을 위한 자바클래스라는 뜻 public class NewlecAppConfig { @Bean // 우리가 만든 객체를 IoC 컨테이너에 담아줌. public Exam exam() { // exam은 bean id와 동일함. 즉, 컨테이너에 담겨질 객체의 이름임. return new NewlecExam(); } } |
ex)

'개발자 공부 > Spring' 카테고리의 다른 글
| AOP(2) - AOP 구현 방식 이해하기 / Spring으로 AOP구현하기(Around Advice) (0) | 2023.04.10 |
|---|---|
| AOP(1) - AOP란? (0) | 2023.04.07 |
| Spring (9) - Annotation을 이용한 객체 생성 / @Controller, @Repository, @Service (0) | 2023.03.28 |
| Spring (8) - Autowired의 위치와 Required 옵션 (0) | 2023.03.28 |
| Spring (7) - Annotation 사용의 장점 / @Autowired와 @Qualifier (0) | 2023.03.28 |