Integrate DWR 2 in Spring 2

Source: Internet
Author: User
Integrate DWR 2 in spring 2

A few days ago I read an article about integrating DWR 2 in spring 2, Ajax, DWR and spring. Recently, if you want to give it a try, download the source code and check it again. An XML verification error is returned at runtime. Finally, the problem was solved.

Spring 2 configuration based on XML Schema

As we all know, spring 2 greatly simplifies its configuration through XML Schema configuration, and makes third-party extensions possible. Configure the following code:

<? XML version = "1.0" encoding = "UTF-8"?>

<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">

<! -- <Bean/> definitions here -->

</Beans>

Listing 1 applicationContext. xml

I wonder if you ever thought about where the spring-beans-2.0.xsd is located? In fact, you can use Eclipse to open the Spring jar package, expand the META-INF, and double-click to open the spring. schemas file, the content is as follows:

Http/: // www.springframework.org/schema/beans/spring-beans-2.0. xsd = org/springframework/beans/factory/xml/spring-beans-2.0. xsd

Http/: // www.springframework.org/schema/tool/spring-tool-2.0. xsd = org/springframework/beans/factory/xml/spring-tool-2.0. xsd

Http/: // www.springframework.org/schema/util/spring-util-2.0. xsd = org/springframework/beans/factory/xml/spring-util-2.0. xsd

Http/: // www.springframework.org/schema/aop/spring-aop-2.0. xsd = org/springframework/aop/config/spring-aop-2.0. xsd

HTTP/: // www.springframework.org/schema/lang/spring-lang-2.0. XSD = org/springframework/scripting/config/spring-Lang-2.0. XSD

HTTP/: // www.springframework.org/schema/tx/spring-tx-2.0. XSD = org/springframework/transaction/config/spring-TX-2.0. XSD

HTTP/: // www.springframework.org/schema/jee/spring-jee-2.0. XSD = org/springframework/EJB/config/spring-jee-2.0. XSD

HTTP/: // www.springframework.org/schema/beans/spring-beans.xsd = org/springframework/beans/Factory/XML/spring-beans-2.0. XSD

HTTP/: // www.springframework.org/schema/tool/spring-tool.xsd = org/springframework/beans/Factory/XML/spring-tool-2.0. XSD

HTTP/: // www.springframework.org/schema/util/spring-util.xsd = org/springframework/beans/Factory/XML/spring-util-2.0. XSD

HTTP/: // www.springframework.org/schema/aop/spring-aop.xsd = org/springframework/AOP/config/spring-AOP-2.0. XSD

HTTP/: // www.springframework.org/schema/lang/spring-lang.xsd = org/springframework/scripting/config/spring-Lang-2.0. XSD

HTTP/: // www.springframework.org/schema/tx/spring-tx.xsd = org/springframework/transaction/config/spring-TX-2.0. XSD

HTTP/: // www.springframework.org/schema/jee/spring-jee.xsd = org/springframework/EJB/config/ spring-jee-2.0. XSD

Listing 2 spring. Schemas

From the above files, we can see that the XML sechema file is located in the class package.

XML schema file in DWR 2.0 RC 2

According to the above description, I open the spring. schemas file in the DWR jar package. The content is as follows:

HTTP/: // www.directwebremoting.org/schema/spring-dwr-2.0. XSD = org/directwebremoting/spring-DWR-2.0. XSD

Then, follow the path above to open the spring-dwr-2.0.xsd file with the following content:

<? XML version = "1.0" encoding = "UTF-8" standalone = "no"?>

<! -- Copyright information is omitted -->

<XSD: schema xmlns = http://www.directwebremoting.org/schema/spring-dwr

Xmlns: XSD = http://www.w3.org/2001/XMLSchema

TargetNamespace = http://www.directwebremoting.org/schema/spring-dwr

ElementFormDefault = "qualified"

AttributeFormDefault = "unqualified">

<! -- Omitted the specific definition -->

</Xsd: schema>

List 3 spring-dwr-2.0.xsd

The file spring-dwr-2.0.xsd tells us that its namespace should be "http://www.directwebremoting.org/schema/spring-dwr.pdf, so we should use the above namespace When configuring spring 2, as shown in the following code snippet:

<? 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.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd">

<Dwr: configuration>

<Dwr: convert class = "net. blogjava. max. pws. domain. Album" type = "bean">

<Dwr: exclude method = "photos"/>

</Dwr: convert>

<Dwr: convert class = "net. blogjava. max. pws. domain. Photo" type = "bean">

<Dwr: exclude method = "original, poster, thumb, full, album"/>

</Dwr: convert>

</Dwr: configuration>

<Bean id = "ajaxFacade" class = "net. blogjava. max. pws. web. ajax. AjaxFacade">

<Dwr: remote javascript = "AjaxFacade"/>

<Property name = "personalWebSite" ref = "personalWebSite"/>

</Bean>

</Beans>

Listing 3. ajaxContext. xml

Configure WEB-INF/Web. xml

Through the above configuration, we can save the dwr. xml configuration, But When configuring the dwr Servlet in web. xml, we need to use the new Servlet class. The configuration code snippet is as follows:

<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>

<Load-on-startup> 1 </load-on-startup>

</Servlet>

<Servlet-mapping>

<Servlet-name> dwr </servlet-name>

<Url-pattern>/dwr/* </url-pattern>

</Servlet-mapping>

Listing 4 web. xml

Summary

By integrating DWR 2 configuration in Spring 2, you can centrally manage application configurations to solve the problem of configuration file flooding in Java EE development to a certain extent.

Article Source: http://www.blogjava.net/max/archive/2007/01/31/97009.html

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.