본문 바로가기

Programming/SpringFrameWork

[펌]Spring 플러그인 설치(이클립스)

Spring

 

<이클립스 플러그인 설치>

http://eclipse.org 에서 오른쪽 상단의 플러그인 아이콘 클릭

사용자 삽입 이미지




Spring 플러그인을 찾아 들어가서 Update Site URL을 복사

사용자 삽입 이미지

이클립스 메뉴에서 help -> software updates.. -> Available Software 탭 -> Add Site -> 주소 붙여넣기 ->

사용자 삽입 이미지

추가 되면 체크하고 Install. 완료 -> 이클립스 자동 재시작

사용자 삽입 이미지

  • 창시자 : 로드 존슨
  • 스프링 프레임웍을 지원하기 위해서 Dao와 같이
  • 경량
  • 인터페이스와 구현을 분리 시켜라(객체지향)
  • Dao와 의존 관계
  • 스프링 컨테이너가 applicationContext.xml(스프링설정파일)을 바로 수행
  • biz, dao를 각각 interface와 구현 클래스로 구분
  • 컨테이너에 미리 뛰워 놓고 요청시 바로바로 응답해 준다.(빠른응답)
  • DI container = Ioc(inversion of control)
  • hivemind spring

구현

  • 프로젝트에서 마우스 오른쪽 -> Spring tools -> Add Spring Project Nature => Spring Elements 생성됨
  • WEB-INF/applicationContext.xml  OR  WEB-INF/conf/applicationContext.xml 등으로 생성 가능
  • 폴더에 마우스 오른쪽 new -> other -> Spring -> Spring Bean Definition => applicationContext.xml 생성
  • applicationContext.xml (스프링 설정 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">

     <!-- addrService는  addressDao를 생성자를 통하여 주입한다.-->
     <bean name="addrService" class="mhpro.address.biz.impl.AddrServiceImpl">
      <constructor-arg>
       <ref bean="addressDao"/>
      </constructor-arg>
     </bean>
     
     <bean name="addressDao" class="mhpro.address.dao.impl.MockAddrDao">
     </bean>
     
    </beans>

  • util.AddrServiceHelper.java (lookup 하기 위한 클래스)

    package mhpro.address.util;

    import javax.servlet.ServletContext;

    import org.springframework.web.context.WebApplicationContext;
    import org.springframework.web.context.support.WebApplicationContextUtils;

    import mhpro.address.biz.AddrService;

    public class AddrServiceHelper {
     public static AddrService getAddrService(ServletContext ctx) {
      WebApplicationContext wac =
       WebApplicationContextUtils.getWebApplicationContext(ctx);
     
      return (AddrService) wac.getBean("addrService");
     }
    }

  • web.xml (applicationContext 설정 부분)

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/conf/applicationContext*.xml</param-value>
</context-param>
 
<listener>
<listener-class>
    org.springframework.web.context.ContextLoaderListener
</listener-class>

</listener>

  • ViewAllAction.java (액션에서 객체 생성 부분)

AddrService service =
   AddrServiceHelper.getAddrService(
    this.getServlet().getServletContext());


정리/요약

  • Service, Dao => Interface/Impl 분리
  • Service 클래스 생성자 사용 Dao를 주입(Injection)받음
  • applicationContext.xml 파일에 위 클래스 등록
  • web.xml에 Spring 관련 엘레먼트 등록(2가지)
  • ServiceUtil 생성(for lookup)
  • 마지막, Action 단(Controller)에서 Service 호출 및 사용

 

Spring DI (Dependency Injection, 의존 삽입)

  • lookup - regist (룩업을 할때 등록된 이름으로 등록한다)
  • WAS내에 여러개의 프로젝트가 있을경우 세션을 다 같이 사용하려면 Portal Server
  • Portlet : Portal 속에 들어가있는 구성원
  • SSO(Single Sign On) : 한번 로그인 하면 다른 사이트에 가도 SSO에 묶인 사이트엔 세션 정보가 남아있다.
  • Object -> Component -> JavaBeans
  • Bean은 컨테이너에 의해 자동적으로 관리를 받는다.
  • 프로퍼티(property) 설정으로 setter, getter 방식으로 사용
  • 의존 관계 자동 설정
    • applicationContext.xml -> <beans ....... autowire="byName"/>
      • 이름에 맞게 자동으로 관계 맺어줌. property랑 이름이 같은 것 끼리.
    • 설정 파일의 크기가 줄어들지만 규모가 클때는 복잡해지기때문에 디버깅이 어려워 명시적으로 적어준다.
  • 어노테이션 (@, 설정)
    • JDK 1.5부터 지원
    • applicationContet.xml 에 설정 대신 소스 코드 자체에 @... 로 설정 가능
    • 변천사 : Source코드 포함 -> TextFile -> XML -> Annotation
    • 소스코드 자체의 설정(ex. @Override : 해당메소드는 반드시 오버라이딩되는 메소드여야만 한다. 아니면 에러)

 

Spring AOP (Aspect Oriented Programming, 바라보는 관점)

[출처] 스프링|작성자 페닐

'Programming > SpringFrameWork' 카테고리의 다른 글

[펌]Spring Framework 따라하기 [1] - 환경 설정  (0) 2008.11.07
[펌]Spring Framework v2.0 - Jar Files  (0) 2008.11.07
[펌]Spring Framework v2.0?  (0) 2008.11.07
[펌]Spring IDE Demo  (0) 2008.11.07
스프링관련글 사이트  (0) 2008.11.05