Bean과 Beans란
Bean
Spring IoC 컨테이너가 관리하는 자바 객체를 의미하며 일반적으로 xml파일에 정의한다.
우리가 new를 사용하여 생성 할 수 있는 객체는 해당 되지 않으며 ApplicationContext.getBean()으로 얻을 수 있다.
즉, ApplicationContext가 만들어서 그 안에 담고 있는 개체를 의미한다.
Bean을 등록하는 방법에는 두가지가 있다.
1. Component Scanning
@ComponentScan 이용
2. 빈 설정파일에 직접 빈을 등록
xml파일에 직접 등록해서 사용. 최근에는 자바 설정파일을 더 사용.
자바 설정 파일은 자바 클래스를 생성해서 작성 가능하며 클래스 이름은 xxxConfiguration과 같이 명명하고 클래스 내에 @Configuration과 @Bean을 사용해 직접 정의한다.
Component기술
<context:component-scan base-package="com.somcat.cpos.persistence"></context:component-scan>
<context:component-scan base-package="com.somcat.cpos.service"></context:component-scan>
@Component는 개발자가 직접 작성한 Class를 Bean으로 등록하기에 위한 어노테이션이다.
java가 maven을 인식해야하는데 maven으로 library에 등록(import해서 사용가능)
----> root-context한테 내가 만든 java들을 읽으라고 시켜야한다.
이게 바로 component scanning기술이다. (component및 injection을 정확하게 해줘야한다.)
base-pacage는 어디서부터 스캔을 할 것인가를 정해주는 부분이다.
'_Programming > Spring' 카테고리의 다른 글
Spring.페이징(Paging) (0) | 2020.07.01 |
---|---|
Spring.파일첨부(file) (0) | 2020.06.30 |
Spring.classpath (0) | 2020.06.29 |
Spring.Settings (0) | 2020.06.25 |
Spring? (0) | 2020.06.25 |