Jetty hot deployment, persistent session, jetty-maven plug-in configuration, mavenjetty plug-in

Source: Internet
Author: User

Jetty hot deployment, persistent session, jetty-maven plug-in configuration, mavenjetty plug-in

Persistent session

Background

Use maven to manage the project and use the jetty plug-in to start the project. Although jetty is a hot deployment, jetty without configuration is not really a hot deployment. This is because the session will be lost every time you perform hot deployment before configuration. This results in data loss during the test. It is troublesome to repeat it again.

I am using jetty-maven-plugin. I will not talk about some basic configurations of this plug-in, but there are a lot of online resources.

Configuration code pom

  

<Plugin> <groupId> org. mortbay. jetty </groupId> <artifactId> jetty-maven-plugin </artifactId> <version> 7.4.3.v20151120.01 </version> <configuration> <! -- When specifying a port, configure the jetty plug-in the setting file --> <connectors> <connector implementation = "org. eclipse. jetty. server. bio. socketConnector "> <port> 9090 </port> <maxIdleTime> 60000 </maxIdleTime> </connector ctor> </connectors> <scanIntervalSeconds> 1 </scanIntervalSeconds> <stopKey> foo </stopKey> <stopPort> 9999 </stopPort> <webAppConfig implementation = "org. mortbay. jetty. plugin. jettyWebAppContext "> <! -- Generally the project name --> <contextPath>/study-ssh </contextPath> <sessionHandler implementation = "org. eclipse. jetty. server. session. sessionHandler "> <sessionManager implementation =" org. eclipse. jetty. server. session. hashSessionManager "> <! -- Used to store persistent session paths --> <storeDirectory> doc/jetty-sessions </storeDirectory> <idleSavePeriod> 1 </idleSavePeriod> </sessionManager> </sessionHandler> </webAppConfig> </configuration> </plugin>

Simple test code

  

String str = (String) ActionContext.getContext().getSession().get("msg");        System.out.println("str11111111111===="+str);        ActionContext.getContext().getSession().put("msg", "Hello World from Session!");        String stra = (String) ActionContext.getContext().getSession().get("msg");        System.out.println("str33333333===="+stra);

Start jetty console output

  

14-07-09 09:10:51. 916: INFO: jetty-7.4.3.v201107012014-07-09 09:10:52. 754: INFO: No Transaction manager found-if your webapp requires one, please configure one.2014-07-09 09:10:52. 933: INFO:/study-ssh: Set web app root system property: 'webapp. root '= [E: \ study \ My-keple-workspace \ study-ssh \ src \ main \ webapp] 09:10:52. 934: INFO:/study-ssh: Initializing log4j from [classpath: log4j. properties] 2014 -09:10:52-09. 992: INFO:/study-ssh: Initializing Spring root WebApplicationContext2014-07-09 09:10:54. 489: INFO: started o. m. j. p. jettyWebAppContext {/study-ssh, file:/E:/study/My-keple-workspace/study-ssh/src/main/webapp/}, file:/E: /study/My-keple-workspace/study-ssh/src/main/webapp/09:10:55. 235: INFO: Started SocketConnector@0.0.0.0: 9090 STARTING [INFO] Started Jetty Server [INFO] Starting SC Anner at interval of 1 seconds. logging Hibernate: select docmodel0 _. UUID as UUID0 _, docmodel0 _. CREATE_DATE as CREATE2_0 _, docmodel0 _. CREATE_USER_UUID as CREATE3_0 _, docmodel0 _. MEMO as MEMO0 _, docmodel0 _. SHOW_ID as SHOW5_0 _, docmodel0 _. SRC as SRC0 _, docmodel0 _. STATE as STATE0 _, docmodel0 _. TITLE as TITLE0 _, docmodel0 _. WORKFLOW_STATE as WORKFLOW9_0 _ from TBL_DOC docmodel0 _ exit str11111111111 === nullstr33333 333 === Hello World from Session!

Console after modifying action class name

  

09:14:10. 058: INFO: No Transaction manager found-if your webapp requires one, please configure one.2014-07-09 09:14:10. 211: INFO: study-ssh: Set web app root system property: 'webapp. root '= [E: \ study \ My-keple-workspace \ study-ssh \ src \ main \ webapp] 09:14:10. 211: INFO: study-ssh: Initializing log4j from [classpath: log4j. properties] 09:14:10. 260: INFO: study-ssh: Initializing Spr Ing root WebApplicationContext2014-07-09 09:14:11. 531: INFO: started o. m. j. p. jettyWebAppContext {/study-ssh, file:/E:/study/My-keple-workspace/study-ssh/src/main/webapp/}, file:/E: /study/My-keple-workspace/study-ssh/src/main/webapp/[INFO] Restart completed at Wed Jul 09 09:14:12 CST 2014 record log Hibernate: select docmodel0 _. UUID as UUID0 _, docmodel0 _. CREATE_DATE as CREATE2_0 _, docmodel0 _. CREATE_USER_UUID S CREATE3_0 _, docmodel0 _. MEMO as MEMO0 _, docmodel0 _. SHOW_ID as SHOW5_0 _, docmodel0 _. SRC as SRC0 _, docmodel0 _. STATE as STATE0 _, docmodel0 _. TITLE as TITLE0 _, docmodel0 _. WORKFLOW_STATE as WORKFLOW9_0 _ from TBL_DOC docmodel0 _ exit str11111111111 === Hello World from Session! Str33333333 === Hello World from Session!

We can see that the session can still be obtained after the hot deployment of jetty.

  

Source: http://www.cnblogs.com/Feeling-always-wrong/
This article is copyrighted by the author. You are welcome to repost this article, but you must keep this statement without the author's consent and provide a connection to the original article on the article page.

  

 


In the jetty-maven-plugin web project, an Encoding Error is reported when the code is run. I use GBK. In tomcat, java. lang. IllegalArgumentException :! Utf8
At org. eclipse. jetty. util. Utf8StringBuilder. append (Utf8StringBuilder. java: 119)
At org. eclipse. jetty. util. UrlEncoded. decodeUtf8To (UrlEncoded. java: 462)

The third sentence is that the jetty-maven-pluginUrlEncoded attribute configuration error is not called utf8 encoding. It should be UTF-8. Check whether the UrlEncoded attribute configuration in the jetty-maven-plugin configuration file is changed to UTF-8 or gbk.

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.