[ETC] DWR2.x 와 Spring2.x에서 설정

황제낙엽 2009.03.12 04:00 조회 수 : 305 추천:84

http://yunsunghan.tistory.com/7

DWR 1.x 에서는 설정파일인 dwr.xml이 꼭 필요하다. DWR 2.x에서는 기존방법과 함께 Spring 설정파일로 dwr.xml을 대신 할수 있다.

설정 순서를 보자.

1. web.xml

[DWR 1.x 기존설정]

  <servlet>
    <servlet-name>dwr-invoker</servlet-name>
    <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>true</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
  </servlet-mapping>


[DWR 2.x 신규설정]

 <servlet>
  <servlet-name>dwr</servlet-name>
  <servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>
  <init-param>
   <param-name>debug</param-name>
   <param-value>true</param-value>
  </init-param>
 </servlet>

 <servlet-mapping>
  <servlet-name>dwr</servlet-name>
  <url-pattern>/dwr/*</url-pattern>
 </servlet-mapping>



기존에 사용하는 DWRServlet을 DwrSpringServlet으로 사용하는 점이 다른 것이다.
이것은 ContextLoaderListener에서 읽어 들인다.
만약 SpringMVC를 사용한다면,
위 설정 마져도 생략하고, Controller 설정파일에서 <dwr>Tag를 이용해서  설정 가능하다.
ex) <dwr:controller id="ajaxCommentController" debug="true"/>

2. beans-comment-service.xml

일반적인 Bean 설정파일이다. 보통은 applicationContext.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"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
  xsi:schemaLocation="http://www.springframework.org/schema/beans  
        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
        http://www.directwebremoting.org/schema/spring-dwr
     http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd">                

<description>comment-service</description>
    <bean id="commentRepository" class="net.max.comment.domain.jdbc.JdbcCommentRepositoryImpl"
      p:dataSource-ref="dataSource"
      p:oracleLobHandler-ref="oracleLobHandler"/>

 <bean id="commentService" class="net.max.comment.domain.CommentServiceImpl">
     <dwr:remote javascript="AjaxCommentService"/>   
     <property name="commentRepository" ref="commentRepository"></property>
    </bean>

</beans>

<dwr> Tag를 사용하기 위해서 Spring DTD를 선언해 주고, Ajax로 서비스할 원하는 Bean에
<dwr> Tag를 넣는다.
이때, SpringIDE의 자동완성 기능이 속성에 관한 도움말을 준다.

설정이 끝났다. 기존 방법보다 월등히 간단해 졌고, 관리도 편해 진다.

3. 테스트 페이지

 getComment( "test",939 ,262); 실행시 결과



4. 참고자료
http://bram.jteam.nl/index.php/2007/01/31/spring-dwr-ajax-made-easy/
http://getahead.org/dwr/server/spring