首页 > 代码库 > @RemoteProxy()注释 与@File注释的使用

@RemoteProxy()注释 与@File注释的使用

@RemoteProxy()注释

dwr3.0可以通过全注解的方式,极大的简化了配置,所有xml配置加在一起不超过20行,而且使用更加简单,bean注入的问题也都解决。配置步骤如下:

web.xml的配置文件中,在默认的DispatcherServlet的mapping里加上dwr

<servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/appServlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

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

 

dispatcherServlet的配置文件appServlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:dwr="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 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>
    </interceptors>
    <!-- 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=http://www.mamicode.com/"/WEB-INF/views/" />
        <beans:property name="suffix" value=http://www.mamicode.com/".jsp" />
    </beans:bean>
    <!--<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 name="allowScriptTagRemoting"
            value=http://www.mamicode.com/"true" />
        <dwr:config-param name="crossDomainSessionSecurity"
            value=http://www.mamicode.com/"false" />
    </dwr:controller>
    <beans:bean
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <beans:property name="order" value=http://www.mamicode.com/"1" />
    </beans:bean>
    <beans:bean
        class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
        <beans:property name="order" value=http://www.mamicode.com/"2" />
    </beans:bean>
    <!--添加结束-->
</beans:beans>

配置完毕,使用的方法和上文类似,注意的是@RemoteProxy标注的远程类一定要加上name属性,不然启动会报错,如:

@Service
@RemoteProxy(name = "GeneralContentManagementService")
public class GeneralContentManagementService {

    @RemoteMethod
    public void aaa()
    {
    }
}

 

@RemoteProxy()注释 与@File注释的使用