Spring-loaded based hot deployment

After JDK1.5, java.lang.instrument.Instrumentation is provided, that is, the java agent mechanism can realize the redefinition and retransform of the class, and it can realize the hot replacement of the class, but unfortunately the function is very limited.
For work needs, I recently researched the implementation of hot deployment and encountered an open source project spring-loaded. I read the official introduction document: I found that its functions are much more powerful than those that come with JDK.
After my own attempts, I found that using the spring-loaded project, which is an agent based on javaAgent, can indeed achieve hot deployment of java applications. The following describes how to introduce spring-loaded into the project. We can run the code below and modify the A.say() method to see if it can be changed dynamically without restarting the JVM.
public class SpringLoadTest
{
public static void main(String[] args) throws Exception
{
SpringLoadTest test = new SpringLoadTest();

while (true)
{
test .say();
Thread.sleep(3000);
}
}
public void say() {
System.out.println("spring-loaded testing...");
}
}
In order to use spring-loaded to achieve hot deployment, we only need to add the following startup parameters when starting the JVM -javaagent:springloaded-1.2.5.RELEASE.jar -noverify
If it is started through eclipse, then you can run confiuration Set it in, as shown in the figure below:
If it is started through eclipse, you can set it in the run configuration. 
Next, let's see how to use spring-loaded in tomcat to realize the hot deployment of war package. Put the downloaded springloaded-1.2.5.RELEASE.jar in the %TOMCAT_HOME%/bin/ directory, and then modify catalina.bat

set JAVA_OPTS=-javaagent:springloaded-1.2.5.RELEASE.jar -noverify in

this directory The configuration of spring-loaded under tomcat is completed, which can detect web applications deployed under tomcat, and realize hot deployment of applications without restarting tomcat.
Next, let's see how to use spring-loaded in resin to implement hot deployment of war packages. Put the downloaded springloaded-1.2.5.RELEASE.jar in the %RESIN_HOME%/lib/ directory, then modify resin.xml in the resin configuration directory, and add the following configuration in <server-default>:
<jvm-arg> -javaagent:springloaded-1.2.5.RELEASE.jar</jvm-arg>
<jvm-arg>-noverify</jvm-arg>
This completes the configuration of spring-loaded under resin, can detect web applications deployed under resin, and realize hot deployment of applications without restarting resin.
Note that if Error opening zip file or jar manifest missing:
javaagent:springloaded-1.2.5.RELEASE.jar appears,
you can change this to the absolute path of the jar.
At present, the latest version of the jar package is springloaded-1.2.5.RELEASE.jar. The download method is as follows:
The external network can go to github to get the latest version
https://github.com/spring-projects/spring-loaded

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326853665&siteId=291194637