I want to fly higher
programming Explorer
posts - 114,comments - 263,trackbacks - 0
1.项目地址
    https://github.com/spring-projects/spring-loaded

2.介绍
    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.

3.小试牛刀
    1.下载spring-loaded:    
        http://repo.spring.io/simple/libs-release-local/org/springframework/springloaded/1.2.3.RELEASE/springloaded-1.2.3.RELEASE.jar

    2.代码示例(eclipse运行)
package com.mavsplus.example.springloaded;

import java.util.concurrent.TimeUnit;

/**
 * <a href="https://github.com/spring-projects/spring-loaded"></a>
 * 
 * @author landon
 * @since 1.8.0_25
 
*/
public class SpringLoadedExample {

    public static void main(String[] args) throws Exception{
        Reload reload = new Reload();

        while (true) {
            reload.load();
            
            TimeUnit.SECONDS.sleep(3);
        }
    }

    public static class Reload {

        public void load() {
            System.out.println("load!");
        }
    }
}

    3.运行配置VM arguments

    
        PS:Maven工程,springloaded-1.2.3.RELEASE.jar放在了src/main/resources目录

        4.运行:
            程序每隔3s输出load

        5.直接修改load方法的输出,输出reload,直接保存即可,神奇的事情出现,我们在未重启application的情况下,进行了代码的reload

            





4.后续会结合源代码以及更深层次的例子进行剖析

posted on 2015-06-19 14:35 landon 阅读(5370) 评论(3)  编辑  收藏 所属分类: JVMHotSwap

FeedBack:
# re: Spring-Loaded 使用Ⅰ-Getting Started
2015-09-16 16:58 | cero
我在项目中引入了springloaded之后,处理请求并返回就会报
java.lang.String cannot be cast to org.springframework.http.MediaType
这个错 是为什么呢?  回复  更多评论
  
# re: Spring-Loaded 使用Ⅰ-Getting Started
2015-12-03 13:26 | ztr323
按照上面的设置,为什么没有反应?代码改变之后输出还是原来的?  回复  更多评论
  
# re: Spring-Loaded 使用Ⅰ-Getting Started
2015-12-03 14:58 | ztr323
原来部分jvm版本不行啊  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: