Combine DWR with spring

Source: Internet
Author: User

In the blog reposted in the previous article, it is the Getting Started tutorial of DWR. Through the previous blog, we can get a preliminary understanding of the principles of DWR and the process of using DWR.

In the previous blog, the classes exposed are DWR and new are instantiated. How can I use the instantiated classes in spring containers?

The procedure is as follows:

In the previous blog, you do not need to change the specific exposure class and JSP.

First: since spring is used, configure spring in Web. xml.

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">  <servlet>    <servlet-name>dwr</servlet-name>    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>    <init-param>      <param-name>debug</param-name>      <param-value>true</param-value>    </init-param>        <init-param>                  <param-name>crossDomainSessionSecurity</param-name>                  <param-value>false</param-value>           </init-param>    </servlet>  <servlet-mapping>    <servlet-name>dwr</servlet-name>    <url-pattern>/dwr/*</url-pattern>  </servlet-mapping>    <listener>     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>    <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>/WEB-INF/applicationContext.xml</param-value>  </context-param></web-app>

2. Modify the DWR. xml file:

<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype DWR public "-// getahead limited // DTD direct Web remoting 2.0 //" http://getahead.org/dwr/dwr20.dtd "> <DWR> <allow> <! -- Service is used on front-end JS --> <create creator = "Spring" javascript = "service"> <Param name = "beanname" value = "servicemanager"/> </create> </allow> </DWR>

Third: configure the spring core configuration file:

<?xml version="1.0" encoding="UTF-8"?><beansxmlns="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.5.xsd">   <bean name="serviceManager" class="com.test.Service"/> </beans>

OK. This is OK, which is very simple.

The value in the beanname parameter in DWR. XML is the same as the bean name in the spring configuration file.

Each method called in DWR. xml needs to be created. The Creator in "CREATE" has multiple types, which are new by default.

It can also be the Spring framework, struts, JSF, and pageflow. If you are interested, try again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.