用上面的方法集成虽然可行,但是比较麻烦,需要定义dwrServlet以及把要注册的类写到web.xml中,而且实际应用中会出现注册的远程类里Autowired的bean不能实例化的问题。dwr3.0可以通过全注解的方式,极大的简化了配置,所有xml配置加在一起不超过20行,而且使用更加简单,bean注入的问题也都解决。配置步骤如下:
-
web.xml的配置文件中,在默认的DispatcherServlet的mapping里加上dwr
<
servlet
>
servlet-name
>appServlet</
>
servlet-class
>org.springframework.web.servlet.DispatcherServlet</
>
init-param
>
param-name
>contextConfigLocation</
>
param-value
>/WEB-INF/spring/appServlet/appServlet-context.xml</
>
</
>
load-on-startup
>1</
>
>
servlet-mapping
>
>
url-pattern
>/</
>
>
>
>
>/dwr/*</
>
>
-
dispatcherServlet的配置文件appServlet-context.xml
<?
xml
version
=
"1.0"
encoding
"UTF-8"
?>
beans:beans
xmlns
"<a href="http://www.springframework.org/schema/mvc" "="" style="outline: none; color: rgb(0,109,175); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; Box-sizing: content-Box !important; font-size: 1em !important; min-height: auto !important;">http://www.springframework.org/schema/mvc"
xmlns:xsi
"<a href="http://www.w3.org/2001/XMLSchema-instance" "="" style="outline: none; color: rgb(0,175); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; Box-sizing: content-Box !important; font-size: 1em !important; min-height: auto !important;">http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans
"<a href="http://www.springframework.org/schema/beans" "="" style="outline: none; color: rgb(0,175); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; Box-sizing: content-Box !important; font-size: 1em !important; min-height: auto !important;">http://www.springframework.org/schema/beans"
xmlns:context
"<a href="http://www.springframework.org/schema/context" "="" style="outline: none; color: rgb(0,175); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; Box-sizing: content-Box !important; font-size: 1em !important; min-height: auto !important;">http://www.springframework.org/schema/context"
xmlns:dwr
"<a href="http://www.directwebremoting.org/schema/spring-dwr" "="" style="outline: none; color: rgb(0,175); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; Box-sizing: content-Box !important; font-size: 1em !important; min-height: auto !important;">http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.directwebremoting.org/schema/spring-dwr <a href="http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd" "="" style="outline: none; color: rgb(0,175); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; Box-sizing: content-Box !important; font-size: 1em !important; min-height: auto !important;">http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
annotation-driven
/>
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
resources
mapping
"/resources/**"
location
"/resources/"
/>
interceptors
beans:bean
class
"com.panguso.op.data.manager.interceptor.LogInterceptor"
></
beans:bean
>
>
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
beans:bean
class
"org.springframework.web.servlet.view.InternalResourceViewResolver"
>
beans:property
name
"prefix"
value
"/WEB-INF/views/"
/>
"suffix"
".jsp"
/>
>
<!--<view-controller path="/" view-name="index" /> -->
context:component-scan
base-package
"com.panguso.op.data.manager"
/>
<!-- 从这行往下是要添加的 -->
context:annotation-config
/>
dwr:configuration
/>
dwr:annotation-config
/>
dwr:url-mapping
/>
dwr:controller
id
"dwrController"
debug
"true"
>
dwr:config-param
"allowScriptTagRemoting"
value
/>
"crossDomainSessionSecurity"
"false"
/>
dwr:controller
>
beans:bean
"org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"
>
"order"
"1"
/>
>
beans:bean
"org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"
>
"2"
/>
>
beans:bean
"org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"
>
"3"
/>
"true"
"alwaysUseFullPath"
/>
"mappings"
>
beans:props
>
beans:prop
key
"/dwr/**"
>dwrController</
beans:prop
>
>
beans:property
>
>
<!--添加结束-->
beans:beans
>