[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 설정을 많이 줄이지 않을까 한다.
번호 제목 글쓴이 날짜 조회 수
81 마우스 드래그(drag)시 iframe 위에서 컨트롤 잃는 현상과 해결 방안 황제낙엽 2017.12.12 18478
80 매우 간단한 AJAX 예제 - prototype.js 이용 (JSP) 황제낙엽 2007.08.24 7497
79 [re] XML+JS 연동 다중셀렉트박스 (2) - [AJAX] <font color="brown">(MS Explorer 전용)</brown> 황제낙엽 2006.02.22 1559
78 Redux: React 앱의 효율적인 데이터 교류 file 황제낙엽 2020.05.19 740
77 json을 이용한 로그인 구현 file 황제낙엽 2011.03.25 601
76 How Prototype extends the DOM (Prototype으로 DOM을 확장하는 법) 황제낙엽 2011.03.24 444
75 $.ajax() 공략 file 황제낙엽 2011.03.27 415
74 Dojo로 HTML 위젯 개발하기 - Dojo HTML 위젯 황제낙엽 2009.03.18 363
73 Building Your Own Widget Library with YUI 황제낙엽 2009.04.16 321
72 15+ jQuery Popup Modal Dialog Plugins and Tutorials 황제낙엽 2011.03.30 280
71 XML+JS 연동 다중셀렉트박스 (1) - [AJAX] <font color="brown">(MS Explorer 전용)</brown> 황제낙엽 2005.12.02 241
70 Jasmine 관련 황제낙엽 2020.01.13 240
69 다섯 가지의 Ajax 우수 사례 황제낙엽 2011.04.07 219
» Spring에서 DWR Annotation 사용하기 file 황제낙엽 2009.10.28 151
67 [펌] 6. DOJO AND JSON file 황제낙엽 2009.03.11 137
66 Ajax 관련 사이트 정리 황제낙엽 2006.04.20 132
65 웹 개발 패러다임의 전환 - Flex와 Ajax의 동거 황제낙엽 2006.12.21 125
64 XML+JS 연동 다중셀렉트박스 (1) - [AJAX] <font color="brown">(MS Explorer 전용)</brown> 황제낙엽 2005.12.02 125
63 DWR 2.0 and Spring 2.x - The DWR namespace handler 황제낙엽 2009.05.16 124
62 관심 사이트 황제낙엽 2009.03.12 116