Spring Boot Perfect Integration dwr3.0.2-release

Source: Internet
Author: User
Tags xmlns

First step: Register Springdwrservlet into the spring container

Import Java.util.HashMap;

Import Java.util.Map;
Import Org.springframework.boot.web.servlet.ServletRegistrationBean;
Import Org.springframework.context.annotation.Bean;
Import org.springframework.context.annotation.Configuration;

Import Org.springframework.context.annotation.ImportResource; /** * Register Springdwrservlet to spring container * * @author Xu Yu * @since JDK1.7 * @version November 28, 2017 Xu Yu new */@Configuration @i Mportresource ("Classpath:dwr-spring-config.xml") public class Springbootdwrservletregister {/** * @param sp Ringdwrservlet Springdwrservlet * @return Servletregistrationbean * * @Bean public Servletregistrationbea N Registdwrservlet (Springdwrservlet springdwrservlet) {Servletregistrationbean servletregister = new ServletRegis
        Trationbean (Springdwrservlet, "/dwr/*");
        map<string, string> initparameters = new hashmap<string, string> ();
        Initparameters.put ("Debug", "true"); Servletregister.setinitparameters (inItparameters);
    return servletregister; }
    
}


Step two: Override Dwrspringservlet to make the instance of the DWR proxy in the spring container

Import Javax.servlet.ServletConfig;
Import Org.directwebremoting.impl.StartupUtil;
Import Org.directwebremoting.spring.DwrSpringServlet;
Import Org.directwebremoting.spring.SpringContainer;
Import Org.springframework.context.ApplicationContext;

Import org.springframework.stereotype.Component; /** * Springdwrservlet * * <pre> * rewrite Dwrspringservlet to make the instance of the DWR proxy in the spring container * </pre> * * @author Xu Yu * @
    
    Since JDK1.7 * @version November 28, 2017 Xu Yu NEW */@Component public class Springdwrservlet extends Dwrspringservlet {
    
    /** */private static final long serialversionuid = 1L; @Override protected Springcontainer CreateContainer (ServletConfig servletconfig) {ApplicationContext Appconte
        
        XT = Getapplicationcontext (Servletconfig.getservletcontext ());
        Springdwrcontainer Springcontainer = new Springdwrcontainer ();
        Springcontainer.setbeanfactory (AppContext); Startuputil.setupdefaultcontainer (Springcontainer, Servletconfig);
    return springcontainer;
 }
    
}


Step three: Spring version DWR container

Import Java.util.Map;
Import org.directwebremoting.extend.ContainerConfigurationException;
Import Org.directwebremoting.spring.SpringContainer;
Import Org.springframework.beans.factory.ListableBeanFactory;

Import Org.springframework.util.ClassUtils;

Import Com.comtop.cap.common.util.StringUtil; /** * Spring Version DWR container * * @author Xu Yu * @since JDK1.7 * @version November 28, 2017 Xu Yu NEW */public class Springdwrcontainer Extends Springcontainer {/** * * @see Org.directwebremoting.spring.springcontainer#addparameter (java. Lang. String, java.lang.Object) */@Override public void Addparameter (string askfor, Object valueparam) throws Cont ainerconfigurationexception {try {class<?> clz = Classutils.forname (askfor, Classutil
            
            S.getdefaultclassloader ()); @SuppressWarnings ("Unchecked") map<string, object> Beansoftype = (map<string, object>) (Listableb
        Eanfactory) beanfactory)        . Getbeansoftype (CLZ);
            if (Beansoftype.isempty ()) {Super.addparameter (askfor, Valueparam); } else if (Beansoftype.size () > 1) {String key = Stringutil.uncapitalize (SpringDwrServlet.class.getSim
                Plename ());
                if (Beansoftype.containskey (key)) {Beans.put (askfor, Beansoftype.get (key));
                } else {throw new containerconfigurationexception ("the corresponding servlet cannot be found in the Spring container:" + key);
            }} else {beans.put (askfor, Beansoftype.values (). iterator (). Next ());
        }} catch (ClassNotFoundException ex) {Super.addparameter (askfor, Valueparam);
 }
        
    }
}


Fourth Step: Container scan configuration file Dwr-spring-config.xml

<?xml version= "1.0" encoding= "UTF-8"?> <beans
xmlns= "Http://www.springframework.org/schema/beans"
       xmlns:context= "Http://www.springframework.org/schema/context"
       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-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 ">
  
   <dwr:configuration/>   
   <dwr: Annotation-scan base-package= "Com.xxx" scandatatransferobject= "true" scanremoteproxy= "true"/>   
</beans >

Summary: DWR This framework follow-up personnel maintenance less, some things according to the official website to still not work, need to see the source rewrite, but it is more convenient to use,

Not clear yourself see DWR source, and view Spring boot website and DWR official website






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.