[ETC] Spring에서 DWR Annotation 사용하기

황제낙엽 2009.10.28 03:52 조회 수 : 151 추천:118

sitelink1  
sitelink2  
sitelink3 http://1 
extra_vars4 ko 
extra_vars5 http://yunsunghan.tistory.com/tag/DWR3.0 
extra_vars6 sitelink1 

기존에 어노테이션(annotation)을 사용하지 않은 연동 방법은 다음과 같다.

<!-- DTO 객체 -->
 <dwr:configuration>
    <dwr:convert type="bean" class="net.max.account.Account"/>
 </dwr:configuration>

<!-- Ajax 서비스 -->
 <bean id="accountService" class="net.max.account.AccountServiceImpl">
     <dwr:remote javascript="XmlAccountService">   
         <dwr:include method="getAccount" />
      </dwr:remote>
 </bean>



실행 결과


이와같은 설정에서 Ajax 서비스가 많으면 많을수록 XML은 길어 진다.
이것을 Annotation으로 바꿔보자.(web.xml은 기존 설정과 같으니 따로 변경할 필요가 없다.)
기존의 서비스 클래스에 @RemoteProxy, @RemoteMethod를 다음과 같이 붙여준다.(붉은색이 변경된 부분이다.)

@Service
@RemoteProxy(name="AjaxAccountService")
public class AccountServiceImpl implements AccountService {
 
 @RemoteMethod
 public Account getAccount(String id) {
  return new Account(id);
 }
}



@RemoteProxy의 name속성은 외부에 표현될(*.js)파일 이름이 된다. 즉 AjaxAccountService.js 파일로 생성되는 이름이다.
설정은 아래와 같다.(붉은색이 변경된 부분이다.)

<beans xmlns="http://www.springframework.org/schema/beans"
  ......
  xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
  xmlns:dwra="http://www.directwebremoting.org/schema/spring-dwr-annotations"
  xsi:schemaLocation="
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                .....
                http://www.directwebremoting.org/schema/spring-dwr
                http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd
                http://www.directwebremoting.org/schema/spring-dwr-annotations
                http://www.directwebremoting.org/schema/spring-dwr-annotations.xsd">

 <dwr:configuration>
  <dwr:convert type="bean" class="net.max.account.Account"></dwr:convert>
 </dwr:configuration>
 <dwra:annotation-config />



dwra 라는 테그는 원래 없다. 그러니 annotation-config라는 것은 직접 구현해야 한다. 이러한 기능을 하는 것은 DWR3.0에서 지원될것 같다. (하지만 현재는 안된다는거....또한 아직 M2 버젼을 다운받아 테스트 하면 오류가 났다.) 그래서 외국 포험을 뒤져보니 구현한것이 있다. 그 jar를 파일을 받아 classpath 에 넣으면 해당 테크가 잘 동작한다.

행결과




물론 둘다 혼용해서 사용이 가능하다.


별다른 잇점은 없지만 DWR 기반의 프로젝트라면 XML 설정을 많이 줄이지 않을까 한다.
번호 제목 글쓴이 날짜 조회 수
20 DWR을 이용해서 객체를 JSON으로 변환하기 황제낙엽 2011.03.25 34
19 YUI 스크랩 황제낙엽 2009.03.12 16
» Spring에서 DWR Annotation 사용하기 file 황제낙엽 2009.10.28 151
17 DWR 2.0 and Spring 2.x - The DWR namespace handler 황제낙엽 2009.05.16 124
16 Building Your Own Widget Library with YUI 황제낙엽 2009.04.16 321
15 YUI 응용프로그램 만들기 (Writing Your First YUI Application) 황제낙엽 2009.03.12 32
14 MethodChain이란? 황제낙엽 2009.03.12 33
13 DWR2.x 와 Spring2.x에서 설정 황제낙엽 2009.03.12 15
12 [guni] DWR 사용시 Session 값 얻기 황제낙엽 2009.03.12 18
11 [guni] Spring + DWR 을 이용한 Form Submission처리... 황제낙엽 2009.03.12 9
10 [Whiteship's Note] Spring + Ajax with DWR (Revolution) file 황제낙엽 2009.03.12 68
9 [Whiteship's Note] Spring + Ajax with DWR (Coding) file 황제낙엽 2009.03.12 52
8 [Whiteship's Note] Spring + Ajax with DWR 황제낙엽 2009.03.12 24
7 [흰둥이와 백설이] DWR - Reverse Ajax part 2 : Configuring Reverse Ajax 황제낙엽 2009.03.12 39
6 [흰둥이와 백설이] DWR - Reverse Ajax part1 황제낙엽 2009.03.12 31
5 [흰둥이와 백설이] DWR 사용을 위한 web.xml 설정 방법 황제낙엽 2009.03.12 52
4 [흰둥이와 백설이] Overview Of DWR - DWR : JAVA를 위한 쉬운 AJAX 황제낙엽 2009.03.12 18
3 Direct Web Remoting 황제낙엽 2009.03.12 28
2 Reverse AJAX in DWR 2.0 황제낙엽 2007.08.23 49
1 흰둥이’s DWR 강좌 file 황제낙엽 2007.08.23 45