jetty热部署,持久化session,jetty-maven插件配置

持久化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 [email protected]: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

时间: 2024-08-08 11:37:57

jetty热部署,持久化session,jetty-maven插件配置的相关文章

Eclipse中Maven插件配置

1. Maven插件配置 http://www.blogjava.net/fancydeepin/archive/2012/07/13/eclipse_maven3_plugin.html 2. Maven使用教程 http://www.cnblogs.com/sunddenly/p/4195975.html

在maven多模块结构中,并且使用overlay的情况下使用jetty热部署

在使用maven多模块的结构的时候,同时有多个web工程使用maven-war-plugin的overlay来组织的时候,本地开发时如何在eclipse里面启动容器并且可以热部署调试是个比较麻烦的问题,之前一直使用maven-tomcat-plugin, 不可否认tomcat是最快的,而且也是最方便的,但是有一个问题一直无解,就是overlay支持不好,比如webA有一个a.jsp,webB有一个b.jsp,如果在webB依赖webA,使用overlay打包没有问题,可以把a.jsp和b.jsp

Jrebel实现Jetty 热部署

一直对热部署没有真正实践过.以前搞Websphere application server的时候,就经常有客户问WAS热部署的问题,当时其实不甚了了,记得是在部署应用时选上支持二进制部署即可.具体是不是真的work了,我现在都不确定. 自己做web开发,采用的是嵌入式的Jetty方式,但Jetty不支持class的热部署,不得不经常重启,这很浪费时间.花了小半天研究如何让Jetty支持class的热部署,也没找到好办法.搜索之,发现jrebel这个工具,历史竟然不短,可惜是收费的. 于是找了个破

Eclipse+Tomcat7热部署,jrebel6破解与eclipse配置

换了最新的eclipse,以前很多的插件都用不了,对于web开发的人来说,jrebel这种防重启神器必须要配备,防止修改类名.java文件.配置文件后的tomcat重启. 首先给一个下载地址: 配置与破解的步骤: 假设文件解压在D:/jrebel步骤: 1.eclipse下载jrebe插件,可以FQ去eclipse市场中下载. 2.打开eclipse的window->preference->jrebel,在主页选项卡勾选要热部署的项目.再打开advance选项卡,把jar包的路径指向D:/jr

jetty 热部署

1,在pom.xml文件中配置jetty插件的参数:scanIntervalSeconds <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <configuration> <scanIntervalSeconds>1</scanIntervalSeconds> <stopPo

Eclipse-----jrebel实现jetty热部署

步骤1:下载jrebel解压到任一目录下 步骤2:配置jetty

一段tomcat的maven插件配置

<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <path>/</path> <!--和tomcat服务器通信时使用的url编码字符集--> <c

eclipse maven插件配置,jdk全局版本调整

settings.xml </profiles>标签前追加: <profile>      <id>jdk-1.7</id> <activation>        <activeByDefault>true</activeByDefault>        <jdk>1.7</jdk>      </activation>      <properties>        

Eclipse中使用JRebel实现项目热部署(Maven插件版)

JRebel实现项目热部署(Maven插件版) 热部署,就是在应用运行过程中不进行重启,可直接进行软件升级. 在开发过程中,热部署就是在项目运行过程中变更代码,无需重启服务器即可使代码生效. tomcat可以进行项目热部署,但在类中添加方法或方法名改动时则无法热部署,需要重启服务器,导致浪费大量开发时间在等待项目重启上,通过JRebel可实现绝大部分项目代码改动都能进行热部署. 在安装JRebel插件前建议先把Maven jar包中央仓库的下载地址(默认下载地址是国外的,下载速度比较慢)换成国内