使用spring-loaded开源项目,实现java程序和web应用的热部署
JDK1.5之后提供了java.lang.instrument.Instrumentation,即java agent机制可以实现类的redefinition和retransform。
redefinition相应Instrumentation.redefineClasses()可以实现类的热替换。但遗憾的是功能非常有限。
The redefinition may change method bodies, the constant pool and attributes.
The redefinition must not add, remove or rename fields or methods, change the
signatures of methods, or change inheritance. These restrictions maybe be
lifted in future versions.
近期遇到一个开源项目spring-loaded,看了下官方的介绍文档:发现它功能比JDK自带的强大多了。
Spring Loaded is a JVM agent for reloading class file changes whilst a JVM is running.
It transforms classes at loadtime to make them amenable to later reloading.
Unlike 'hot code replace' which only allows simple changes once a JVM is running
(e.g. changes to method bodies), Spring Loaded allows you to
add/modify/delete methods/fields/constructors.
The annotations on types/methods/fields/constructors
can also be modified and it is possible to add/remove/change values in enum types.
我们能够执行以下的这段代码,然后改动A.say()方法,看看在不重新启动JVM的情况下,能否够动态改变。
package test; import demo.A; public class TestPreMain
{ // -javaagent:springloaded-1.2.0.RELEASE.jar -noverify
public static void main(String[] args) throws Exception
{ A a = new A(); while (true)
{
a.say();
Thread.sleep(3000);
}
}
}
-javaagent:springloaded-1.2.0.RELEASE.jar -noverify
假设是通过eclipse启动,那么能够在run confiuration中进行设置
set JAVA_OPTS=-javaagent:springloaded-1.2.0.RELEASE.jar -noverify
这样就完毕了spring-loaded的安装,可以检測tomcat下部署的webapp,在不重新启动tomcat的情况下。实现应用的热部署。
使用spring-loaded开源项目,实现java程序和web应用的热部署的更多相关文章
- 有哪些值得学习的spring boot开源项目?
1. awesome-spring-boot 首先给大家介绍的就是Spring Boot 中文索引,这是一个专门收集 Spring Boot 相关资料的开源项目,也有对应的导航页面. 产品主页 htt ...
- 优秀的Spring Cloud开源项目整理推荐
无论是对于初学者,还是有一定工作经验的程序员来讲,Spring Cloud开源项目都是一笔宝贵的财富.下面给大家整理了十个优秀的开源项目,分别是spring-cloud-examples.spaasc ...
- IDEA maven 多项目 出现 java 程序包找不到
使用idea 多项目引入的时候,出现报错信息:Error java程序包找不到 解决办法: 我在引入多个项目的时候,他们是在一个目录里面的.我把整个目录引入了进去.结果报依赖包找不到. 把引入的全部项 ...
- Spring Boot 项目在 IntelliJ IDEA 中配置 DevTools 实现热部署(macOS 系统)
要配置的内容: 1.Preference -> Build, Execution, Deployment -> Complier -> Build project automatic ...
- IDEA项目搭建五——使用JRebel插件实现IDEA热部署
使用IDEA开发时修改了html或js或java代码都需要编译启动浪费了很多时间,所以可以借助热部署插件实现自动编码,每次修改完代码保存后就可以刷新页面看效果很方便,热部署工具有很多在此只推荐JReb ...
- Java使用自定义类加载器实现热部署
热部署: 热部署就是在不重启应用的情况下,当类的定义即字节码文件修改后,能够替换该Class创建的对象.一般情况下,类的加载都是由系统自带的类加载器完成,且对于同一个全限定名的java类,只能被加载一 ...
- 基于Java+Spring Boot开源项目JeeSite的Jenkins持续交互介绍
一.实战项目介绍- JeeSite 基于Spring Boot 2.0 数据存储MySQL 语言:Java 规模大小:适中,适合初学者 源码地址:https://gitee.com/thinkgem/ ...
- idea 启动java项目报 java: 程序包org.apache.jasper.tagplugins.jstl.core不存在
File -- Project Structure
- idea启动java Maven项目,出现" java: 程序包xxxx不存在"
解决办法如下:将idea的构建和运行托管到maven下面
随机推荐
- 优动漫 PAINT 导航窗口面板
导航窗口面板用于管理画布的视图.本节将介绍如何在其中缩放.旋转.翻转画布. 如何使用导航窗口面板 使用[导航窗口]面板便于把握整个画布,以下将为您详细介绍. 什么是[导航窗口]面板 [导航窗口]面板用 ...
- html转word文档
html转word文档 package cn.com.szhtkj.util; import java.io.ByteArrayInputStream; import java.io.File; im ...
- php对excel导入导出的支持
闲话不多说了,大家直接进入主题 php对excel的导入: 1.为程序添加一个form表单,为form标签添加“enctype="multipart/form-data"”属性 ...
- Iterator(迭代器) 和generator
数组是可迭代的 var a = []; console.dir(a); 发现这里有一个Symbol.iterator ,说明它是可迭代的. object 是不可以迭代的 var a = {} cons ...
- HNU 13101 The Triangle Division of the Convex Polygon 组合数的因式分解求法
题意: 求第n-2个Catalan数 模上 m. 思路: Catalan数公式: Catalan[n] = C(n, 2n)/(n+1) = (2n)!/[(n+1)!n!] 因为m是在输入中给的,所 ...
- 将Spring Boot应用程序迁移到Java9:兼容性
将 Spring Boot 应用程序迁移到 Java 9:兼容性 随着 Java 9 的到来,关于如何迁移应用程序以使用模块系统有很多的讨论.遗憾的是,大多数文章的焦点都集中于简单的 Hello Wo ...
- 阿里云CentOS系统配置iptables防火墙
虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT.OUTPUT和FORWORD都是ACCEPT的规则 一.检查iptabl ...
- [React] Optimistic UI update in React using setState()
In this lesson we will refactor an existing UI update from a typical loading approach to an optimist ...
- groovy : poi 导出 Excel xlsx
參考 file:///poi-3.10-FINAL/docs/spreadsheet/how-to.html#sxssf text2xlsx.groovy 代码例如以下 package xlsx; i ...
- 【转】dig详解
[root@localhost ~]# dig www.a.com ; <<>> DiG 9.2.4 <<>> www.a.com ;; global ...