- <?xml version="1.0" encoding="UTF-8"?>
- <!-- 빈 등록 방법 5가지중 XML을 사용하는 3가지 방법입니다 -->
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:jdbc="http://www.springframework.org/schema/jdbc"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">
- <!-- 1.bean태그를 사용하여 빈 등록 -->
- <bean id="user" class="domain.User">
- </bean>
- <!-- 2.전용태그를 사용하여 빈 등록 -->
- <jdbc:embedded-database id="embeddedDatabase" type="HSQL">
- </jdbc:embedded-database>
- <!-- 3.stereo type의 annotation을 사용 -->
- <!-- service패키지 아래 모든 스테레오 타입을 빈으로 등록 -->
- <context:component-scan base-package="service"/>
- </beans>
2.User.java
- package domain;
- public class User {
- public void test(){
- }
- }
3.MyService.java
- package service;
- import org.springframework.stereotype.Component;
- public class MyService {
- public void test(){
- }
- }
4.BeanTagTest
- import javax.sql.DataSource;
- import org.springframework.context.support.GenericApplicationContext;
- import org.springframework.context.support.GenericXmlApplicationContext;
- import service.MyService;
- import domain.User;
- public class BeanTagTest {
- GenericApplicationContext ac = new GenericXmlApplicationContext("applicationContext.xml");
- //1.<bean>태그 사용
- User user = ac.getBean("user", User.class);
- user.test();
- //2.전용태그 사용
- DataSource ds = ac.getBean("embeddedDatabase", DataSource.class);
- //2.스테레오타입 애노테이션 & 전용태그 빈 스캔 사용
- MyService myService = ac.getBean("myService", MyService.class);
- myService.test();
- }
- }
http://hsqldb.org/ 다운로드 후 hsqldb와sqltool jar파일을 외부라이브러리에 추가
- XML:<bean>태그
- XML:네임스페이스(스키마등록)와<bean>태그
- XML:스테레오타입 애노테이션과 빈 스캐너
댓글 없음:
댓글 쓰기