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 [email protected]: 9090 Starting [info] started jetty server [info] Starting restart 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 === nullstr33333333 === = 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.