Dwr3.0純注解(純Java Code設置裝備擺設)設置裝備擺設與運用淺析一之零設置裝備擺設文件化。本站提示廣大學習愛好者:(Dwr3.0純注解(純Java Code設置裝備擺設)設置裝備擺設與運用淺析一之零設置裝備擺設文件化)文章只能為提供參考,不一定能成為您想要的結果。以下是Dwr3.0純注解(純Java Code設置裝備擺設)設置裝備擺設與運用淺析一之零設置裝備擺設文件化正文
//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();}
下面我的設置裝備擺設是基於注解版的Dwr Servlet設置裝備擺設(將web.xml外面的servlet設置裝備擺設轉換為了純Java代碼設置裝備擺設),固然也包含前端和後端直接交互的類(
com.g360.bean.reconsole.opcost.AnnualOpCostRequestController,com.g360.bean.security.SessionExpiredParam
)也是應用注解設置裝備擺設的(Dwr注解設置裝備擺設,包含@RemoteProxy,@RemoteMethod),這關於有些注解設置裝備擺設基本的同窗來講能夠比擬輕易看懂,關於首次接觸的有甚麼不懂的可以給我留言哦;
com.g360.bean.security.SessionExpiredParam的注解設置裝備擺設以下所示:
@Component("sessionExpiredParam") @RemoteProxy(creator = SpringCreator.class, scope = ScriptScope.APPLICATION, name = "remote", creatorParams = @Param(name = "beanName", value = "sessionExpiredParam")) public class SessionExpiredParam{ 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); } }
這就是相當於dwr.xml設置裝備擺設文件中以下所示:
<!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>
關於com.g360.bean.reconsole.opcost.AnnualOpCostRequestController來講事理一樣,這裡就不多做解釋了;
關於應用DwrServlet來講要應用純注解設置裝備擺設(不應用dwr.xml)必定要留意在初始化參數時必定要設置裝備擺設 classes這個參數,並且這個參數是這個注解類的全途徑名,有多個的話就應用逗號分隔,這個是特殊主要的哦,由於Dwr3.0似乎還不支撐包掃描,不曉得是須要甚麼設置裝備擺設能力完成照樣怎樣的,假如有哪位仁兄正悅目見,也正好曉得的話請留言費事告知一下,感謝不盡啊!迎接年夜家有甚麼不明確的處所或許有甚麼纰謬的處所,請隨時留言;