标签:style blog http color 使用 文件
持久化session
背景
使用maven管理项目,使用jetty插件启动项目,虽然jetty是热部署的,但是没有配置的jetty并不算真正的热部署。因为在没有配置前每次热部署都会把session丢了。导致测试期间的数据丢失,重来一遍很麻烦。
本人使用的是jetty-maven-plugin,关于这个插件的一些基本配置就不说了,网上很多。
配置代码pom
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>7.4.3.v20110701</version> <configuration> <!-- 指定端口时,要在setting文件中配置jetty插件 --> <connectors> <connector implementation="org.eclipse.jetty.server.bio.SocketConnector"> <port>9090</port> <maxIdleTime>60000</maxIdleTime> </connector> </connectors> <scanIntervalSeconds>1</scanIntervalSeconds> <stopKey>foo</stopKey> <stopPort>9999</stopPort> <webAppConfig implementation="org.mortbay.jetty.plugin.JettyWebAppContext"> <!-- 一般是项目名称 --> <contextPath>/study-ssh</contextPath> <sessionHandler implementation="org.eclipse.jetty.server.session.SessionHandler"> <sessionManager implementation="org.eclipse.jetty.server.session.HashSessionManager"> <!-- 用于存放持久化的session路径 --> <storeDirectory>doc/jetty-sessions</storeDirectory> <idleSavePeriod>1</idleSavePeriod> </sessionManager> </sessionHandler> </webAppConfig> </configuration> </plugin>
简单的测试代码
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);
启动jetty控制台输出
14-07-09 09:10:51.916:INFO::jetty-7.4.3.v20110701 2014-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] 2014-07-09 09:10:52.934:INFO:/study-ssh:Initializing log4j from [classpath:log4j.properties] 2014-07-09 09:10:52.992:INFO:/study-ssh:Initializing Spring root WebApplicationContext 2014-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/ 2014-07-09 09:10:55.235:INFO::Started SocketConnector@0.0.0.0:9090 STARTING [INFO] Started Jetty Server [INFO] Starting scanner at interval of 1 seconds. 记录日志 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_ 退出 str11111111111====null str33333333====Hello World from Session!
修改action类名后控制台
2014-07-09 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] 2014-07-09 09:14:10.211:INFO:study-ssh:Initializing log4j from [classpath:log4j.properties] 2014-07-09 09:14:10.260:INFO:study-ssh:Initializing Spring root WebApplicationContext 2014-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 记录日志 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_ 退出 str11111111111====Hello World from Session! str33333333====Hello World from Session!
可以看到jetty热部署后session还是能拿到的。
出处:http://www.cnblogs.com/Feeling-always-wrong/
本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
jetty热部署,持久化session,jetty-maven插件配置,布布扣,bubuko.com
jetty热部署,持久化session,jetty-maven插件配置
标签:style blog http color 使用 文件
原文地址:http://www.cnblogs.com/Feeling-always-wrong/p/3832912.html