'Simplest Spring 3 Application'에 해당되는 글 1건

  1. 2009.12.21 Simplest Spring 3 Application, 초간단 Spring 3 어플
반응형

출처 : http://dogfeet.tistory.com/159

Ioc.java

01.import java.util.Calendar;
02.import org.springframework.beans.factory.BeanFactory;
03.import org.springframework.beans.factory.xml.XmlBeanFactory;
04.import org.springframework.core.io.ClassPathResource;
05.  
06.public class Ioc {
07.  
08.    private Calendar myCalendar;
09.      
10.    public void setMyCalendar(Calendar cal) {
11.        myCalendar = cal;
12.    }
13.      
14.    @Override
15.    public String toString() {
16.        return "Ioc Class with " + myCalendar;
17.    }
18.      
19.    public static void main(String[] args) {
20.        System.out.println("Spring Study!");
21.        BeanFactory bf = new XmlBeanFactory(new ClassPathResource("beans.xml"));
22.        System.out.println(bf.getBean("ioc"));
23.        System.out.println(bf.getBean("date"));
24.    }
25.}

beans.xml

01.<?xml version="1.0" encoding="UTF-8"?>
04.       xsi:schemaLocation="
07.  
08.  
09.    <bean id="calendar" class="java.util.GregorianCalendar" />
10.      
11.    <bean id="date" class="java.util.Date" />
12.  
13.    <bean id="ioc" class="Ioc">
14.        <property name="myCalendar" ref="calendar" />
15.    </bean>
16.      
17.</beans>

library files

  • commons-logging.jar
  • org.springframework.beans-3.0.0.RC1.jar
  • org.springframework.core-3.0.0.RC1.jar

execution

1.$ javac Ioc.java -cp org.springframework.beans-3.0.0.RC1.jar:org.springframework.core-3.0.0.RC1.jar
2.$ java -cp .:org.springframework.core-3.0.0.RC1.jar:org.springframework.beans-3.0.0.RC1.jar:commons-logging.jar Ioc
3.Spring Study!
4.Nov 10, 2009 5:49:14 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
5.INFO: Loading XML bean definitions from class path resource [beans.xml]
6.Ioc Class with java.util.GregorianCalendar[time=1257842954691,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Seoul",offset=32400000,dstSavings=0,useDaylight=false,transitions=14,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2009,MONTH=10,WEEK_OF_YEAR=46,WEEK_OF_MONTH=2,DAY_OF_MONTH=10,DAY_OF_YEAR=314,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=49,SECOND=14,MILLISECOND=691,ZONE_OFFSET=32400000,DST_OFFSET=0]
7.Tue Nov 10 17:49:14 KST 2009
Posted by 1010