spring 2 통합 Dwr(DWR 설정 을 Spring 설정 파일 에 기록)

Spring 2 는 XML Schema 의 설정 을 바탕 으로 Spring 2 는 XML Schema 설정 방식 을 통 해 설정 을 크게 간소화 하고 제3자 확장 을 가능 하 게 합 니 다.
<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-2.0.xsd" >  
 
 
DWR 의 jar 패키지 에서 META-INF/spring.schemas 파일 을 엽 니 다.내용 은 다음 과 같 습 니 다.
 
http\://www.directwebremoting.org/schema/spring-dwr-2.0.xsd=org/directwebremoting/spring/spring-dwr-2.0.xsd
 
 
Spring 2 를 설정 할 때 이름 공간 에 다음 설정 을 추가 해 야 합 니 다.
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
 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-2.0.xsd 
  http://www.directwebremoting.org/schema/spring-dwr
  http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd">
 
다음은 제 전체 spring 설정 및 자바 류 입 니 다.
 
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
	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-2.0.xsd 
	 http://www.directwebremoting.org/schema/spring-dwr
	 http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd">

	<!-- spring bean   -->
	<bean id="dwrHelper" class="com.DwrHelper">
		<!--      js   -->
		<dwr:remote javascript="dwrHelper"></dwr:remote>
		<property name="service">
			<ref bean="service"/>
		</property>
	</bean>

	<bean id="service" class="com.TestServiceImp"/>
	<!-- end spring bean   -->
</beans>
 
DwrHelper.java
package com;

public class DwrHelper {

	private TestServiceInf service;
	
	public String checkUsername(String name){
		return service.checkedUser(name)?"  ":"        ";
	}
	
	public TestServiceInf getService() {
		return service;
	}

	public void setService(TestServiceInf service) {
		this.service = service;
	}
}
TestServiceInf.java
package com;

public interface TestServiceInf {
	public boolean checkedUser(String userName);
}
 
TestServiceImp.java
package com;

public class TestServiceImp implements TestServiceInf{
	public boolean checkedUser(String userName){
		return userName.equals("callan");
	}
	
}
 
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/applicationContext.xml</param-value>
	</context-param>

	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
	
	<servlet>
		<servlet-name>dwr-invoker</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-invoker</servlet-name>
		<url-pattern>/dwr/*</url-pattern>
	</servlet-mapping>
	
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>
 
index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
                   

좋은 웹페이지 즐겨찾기