Dwr3.0 Pure Annotation (pure Java code Configuration) configuration and application analysis of a zero configuration file _java

Source: Internet
Author: User
Tags stringbuffer
Annotation configuration dwr servletprivate void Initializedwrservlet (ServletContext container) {Dwrservlet
Dwrservlet = new Dwrservlet ();
Servletregistration.dynamic Dynamic = Container.addservlet ("Dwr-invoker", Dwrservlet);
Dynamic.setloadonstartup (2);
Dynamic.setinitparameter ("Debug", "true");
Dynamic.setinitparameter ("pollandcometenabled", "true");
Dynamic.setinitparameter ("activereverseajaxenabled", "true");
Dynamic.setinitparameter ("Maxwaitafterwrite", "1800000");
Dynamic.setinitparameter ("Disconnectedtime", "60000");
Dynamic.setinitparameter ("Classes", dwrannotationclasssconfiguration ());
Dynamic.addmapping ("/dwr/*");} Configure Dwr Annotation classes,comma separatedprivate String dwrannotationclasssconfiguration () {StringBuffer
Config = new StringBuffer ();
Config.append ("Com.g360.bean.reconsole.opcost.AnnualOpCostRequestController");
Config.append (","); Config.append ("Com.g360.bean.security.SessionExpiredParam");
 return config.tostring ();}

My configuration above is based on the annotation version of the DWR servlet configuration (converting the servlet configuration in web.xml to pure Java code Configuration), and of course including the front-end and back-end direct interaction classes (

Com.g360.bean.reconsole.opcost.annualopcostrequestcontroller,com.g360.bean.security.sessionexpiredparam

Note Configuration is also used (DWR annotation configuration, including @remoteproxy, @RemoteMethod), which for some of the annotation configuration based on the students may be easier to read, for the first contact with what do not understand can give me a message oh;

The Com.g360.bean.security.SessionExpiredParam annotation configuration looks like this:

@Component ("Sessionexpiredparam")
@RemoteProxy (creator = springcreator.class, scope = Scriptscope.application, Name = "Remote", Creatorparams = @Param (name = "Beanname", value = "Sessionexpiredparam")) Public
 class sessionexpired param{ 
private static final Logger Logger = Loggerfactory.getlogger (sessionexpiredparam.class); 
public boolean issessionexpire (String sessionId) {return 
null = = Constantcacheservice.getcacheconstant (sessionId );
 @RemoteMethod public void setenabledwrupdate (String sessionId) {
  scriptsession scriptsession = Webcontextfactory.get (). Getscriptsession (); 
 String jsessionid = Scriptsession.gethttpsessionid (); 
String Dwrsessionid = Scriptsession.getid (); 
Logger.info (String.Format ("Set jsessionid = [%s],dwrsession = [%s] Push enabled", Jsessionid,dwrsessionid)); 
Constantcacheservice.putcacheconstant (Constants.push_id+jsessionid, Dwrsessionid); 
} }

This is the equivalent of the Dwr.xml configuration file as follows:

<! DOCTYPE dwr Public "-//getahead limited//dtd Direct Web Remoting 3.0//en" "Http://getahead.org/dwr/dwr30.dtd" >< dwr> 
<allow> <create creator= "new" javascript= "remote" scope= "Application" >  
 <param name= " Class "value=" Com.g360.bean.security.SessionExpiredParam "/> 
 </create> </allow></dwr>

For Com.g360.bean.reconsole.opcost.AnnualOpCostRequestController, the same reason, here is not to do more explanation;

For use of Dwrservlet to use a pure annotation configuration (do not use dwr.xml) must be aware of the initialization of the parameters must be configured classes this parameter, and this parameter is the full path of the annotation class, there are multiple words separated by commas, this is particularly important oh, Because Dwr3.0 does not seem to support packet scanning, do not know what configuration is needed to achieve or how, if there is any one who just see, also happen to know, please leave a message trouble tell, thank you! Welcome to what you do not understand the place or what is wrong, please feel free to leave a message;


Related Article

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.