1. 지시서 작성방식의 변경
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" ..>
<context:componet-scan base-package ="spring.di.ui" />
<bean id="exam" class="spring.di.entity.NewlecExam" />
</beans>
<!----------------------------------------------변경전------------------------------------------!>
@ComponentScan({"spring.di.ui", "spring.di.entity"})
@Configuration
public class NewlecAppConfig {
@Bean //bean이라고하는 어노테이션은 IoC컨테이너에 담는 역할을 함.
public Exam exam() { //exam()을 함수라 생각하지 말고, id로 사용된다고 생각하기
return new NewlecExam();
}
}
<!---------------------------------------변경후-------------------------------------!>
ApplicationContext context = new AnnotationConfigApplicationContext(settingConfig.class);
이제 xml파일을 사용하지않고 class파일을 이용하기 때문에 AnnotationConfigApplicationContext(클래스명);
을 넣어준다. 그럼 이제 xml파일을 사용하지 않고 새로 지정한 class파일을 사용한다.
'개발공부 > Spring' 카테고리의 다른 글
[spring] AOP 자바 코드 이해하기 (0) | 2022.01.26 |
---|---|
[spring] AOP(Aspect Oriented Programming)이란? (0) | 2022.01.26 |
[spring] 특화된 @Component 어노테이션 (@Controller / @Service / @Repository) (0) | 2022.01.25 |
[spring] 어노테이션을 이용한 객체 생성 (0) | 2022.01.25 |
[spring] @Autowired 위치와 required 옵션 (0) | 2022.01.25 |
1. 지시서 작성방식의 변경
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" ..>
<context:componet-scan base-package ="spring.di.ui" />
<bean id="exam" class="spring.di.entity.NewlecExam" />
</beans>
<!----------------------------------------------변경전------------------------------------------!>
@ComponentScan({"spring.di.ui", "spring.di.entity"})
@Configuration
public class NewlecAppConfig {
@Bean //bean이라고하는 어노테이션은 IoC컨테이너에 담는 역할을 함.
public Exam exam() { //exam()을 함수라 생각하지 말고, id로 사용된다고 생각하기
return new NewlecExam();
}
}
<!---------------------------------------변경후-------------------------------------!>
ApplicationContext context = new AnnotationConfigApplicationContext(settingConfig.class);
이제 xml파일을 사용하지않고 class파일을 이용하기 때문에 AnnotationConfigApplicationContext(클래스명);
을 넣어준다. 그럼 이제 xml파일을 사용하지 않고 새로 지정한 class파일을 사용한다.
'개발공부 > Spring' 카테고리의 다른 글
[spring] AOP 자바 코드 이해하기 (0) | 2022.01.26 |
---|---|
[spring] AOP(Aspect Oriented Programming)이란? (0) | 2022.01.26 |
[spring] 특화된 @Component 어노테이션 (@Controller / @Service / @Repository) (0) | 2022.01.25 |
[spring] 어노테이션을 이용한 객체 생성 (0) | 2022.01.25 |
[spring] @Autowired 위치와 required 옵션 (0) | 2022.01.25 |