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를 다음과 같이 붙여준다.(붉은색이 변경된 부분이다.)
@RemoteProxy(name="AjaxAccountService")
public class AccountServiceImpl implements AccountService {
@RemoteMethod
public Account getAccount(String id) {
return new Account(id);
}
}
@RemoteProxy의 name속성은 외부에 표현될(*.js)파일 이름이 된다. 즉 AjaxAccountService.js 파일로 생성되는 이름이다.
설정은 아래와 같다.(붉은색이 변경된 부분이다.)
......
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 설정을 많이 줄이지 않을까 한다.