본문 바로가기

🎧️ 강의듣기

Spring Framework

Spring Framework

    1.

        * 위임 → 참조변수

        class 생성, 소멸에 관한 lifecycle을 관리하는 프레임워크

 

    2. 전처리나 후처리

        * 수동

        new class 생성

        가비지 컬렉션 class 소멸

 

        → mvc model 방법



        spring https://spring.io/

 

Framework

    DI - Dependency Injection (의존 주입)

        class 생성(*), 소멸에 관한 lifecycle을 관리

            생성 + 초기화 위임 → 의존 주입

                주입

                    xml

                    annotation

 

    AOP - Aspect Oriented Programming (관점 중심 프로그래밍)

    전처리 / 후처리

 

    eclipse → 개발

        eclipse + STS

        신형

            spring boot 환경 사용 (자동환경)

        구형

            설정 수동으로

                Java Project + library 수동 추가

                Maven Project + library 설정만

 

전자정부프레임워크

https://www.egovframe.go.kr/

 

이클립스 설정하고오기

 

spring2/HelloBean1.java

package spring2;

public class HelloBean1 implements Hello {

	@Override
	public void sayHello( String name ) {
		System.out.println( name + "님 안녕하세요" );
	}
}

 

spring2/HelloBean2.java

package spring2;

public class HelloBean2 implements Hello {

	@Override
	public void sayHello( String name ) {
		System.out.println( "Hello " + name );
	}
}

 

spring2/Hello.java (인터페이스)

package spring2;

public interface Hello {
	void sayHello( String name );
}

 

spring2/context.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 https://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
	
	<!-- HelloBean1 helloBean1 = new HelloBean1(); 이랑 같은의미 -->
	<bean name="helloBean1" class="spring2.HelloBean1"></bean>
	<bean name="helloBean2" class="spring2.HelloBean2"></bean>

</beans>

 

spring2/ApplicationMain.java

package spring2;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

public class ApplicationMain {

	public static void main(String[] args) {
		
		GenericApplicationContext ctx = new GenericXmlApplicationContext( "classpath:spring2/context.xml" );
		
		Hello hello = (Hello)ctx.getBean("helloBean1");
		hello.sayHello( "홍길동" );
		
		hello = (Hello)ctx.getBean("helloBean2");
		hello.sayHello( "박문수" );
		
		ctx.close();

	}

}

 

Maven 프로젝트로 생성

com.exam.ex02/BoardTO.java

package com.exam.ex02;

public class BoardTO {
	private int seq;
	private String subject;
	
	public int getSeq() {
		return seq;
	}
	public void setSeq(int seq) {
		this.seq = seq;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
}

 

com.exam.ex02/context.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 https://www.springframework.org/schema/beans/spring-beans-4.3.xsd">

	<bean id="to" class="com.exam.ex02.BoardTO" scope="prototype" >
		<property name="seq" value="1" />
		<property name="subject" value="제목" />
	</bean>
</beans>

 

com.exam.ex02/App02.java

package com.exam.ex02;

import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

public class App02 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		GenericXmlApplicationContext ctx = new GenericXmlApplicationContext("classpath:com/exam/ex02/context.xml");
		
		BoardTO to = (BoardTO)ctx.getBean( "to" );
		
		System.out.println( to.getSeq() );
		System.out.println( to.getSubject() );
		
		ctx.close();
	}
}

 

'🎧️ 강의듣기' 카테고리의 다른 글

스프링 프레임워크  (0) 2021.08.09
Spring Framework (2)  (0) 2021.08.06
이클립스 Spring 설정하기  (0) 2021.08.05
Java를 위한 프레임 워크 mybatis  (0) 2021.08.02
jQuery-ui accordion / datepicker / dialog  (0) 2021.07.15