빈 등록 및 빈 설정을 모두 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.xsd>">
</beans>
빈 등록은 XMl, 빈 설정은 자바 어노테이션으로 할 경우 이 포맷을 사용한다.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="<http://www.springframework.org/schema/beans>"
xmlns:context="<http://www.springframework.org/schema/context>"
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.xsd>
<http://www.springframework.org/schema/context> <http://www.springframework.org/schema/context/spring-context.xsd>">
<context:annotation-config/>
</beans>
<bean>
태그를 이용해 빈을 정의한다. <bean>
태그의 필수 속성은 class
하나 뿐이다.
<bean id="studentDao" class="ems.member.dao.StudentDao" />
id
: 빈 이름(고유 식별자) 설정
class
: 빈으로 등록할 Java 클래스 설정
scope
: 빈을 생성하기 위한 방법 설정 (singleton/prototype)
primary
: true 를 지정하여 같은 타입의 빈이 여러 개 일 때 우선적으로 사용할 빈 설정
⇒ 인터페이스를 상속받은 클래스가 여러 개 일 때 primary 를 설정하여 빈의 우선순위를 설정할 수 있다.
lazy-init
: true 를 지정하여 빈을 사용할 때 객체가 생성되도록 설정
init-method
: 빈 객체가 생성될 때 호출할 메소드 설정
destroy-method
: 빈 객체가 소멸될 때 호출할 메소드 설정
autowire
: 자동 주입 설정 (byName/byType/constructor/no)