2009 Nov 10

- by
Sean Lee

Java Spring

Simplest Spring 3 Application, 초간단 Spring 3 어플

Ioc.java

import java.util.Calendar;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

public class Ioc {

    private Calendar myCalendar;

    public void setMyCalendar(Calendar cal) {
        myCalendar = cal;
    }

    @Override
    public String toString() {
        return "Ioc Class with " + myCalendar;
    }

    public static void main(String[] args) {
        System.out.println("Spring Study!");
        BeanFactory bf = new XmlBeanFactory(new ClassPathResource("beans.xml"));
        System.out.println(bf.getBean("ioc"));
        System.out.println(bf.getBean("date"));
    }
}

beans.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">


    <bean id="calendar" class="java.util.GregorianCalendar" />

    <bean id="date" class="java.util.Date" />

    <bean id="ioc" class="Ioc">

    </bean>

</beans>

library files

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

execution

$ javac Ioc.java -cp org.springframework.beans-3.0.0.RC1.jar:org.springframework.core-3.0.0.RC1.jar
$ java -cp .:org.springframework.core-3.0.0.RC1.jar:org.springframework.beans-3.0.0.RC1.jar:commons-logging.jar Ioc
Spring Study!
Nov 10, 2009 5:49:14 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
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]
Tue Nov 10 17:49:14 KST 2009