SpringBoot入门笔记(三)、热加载

1、配置热加载环境,在pom.xml添加如下代码

<build>
    <!--springloader plugin  -->
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <dependencies>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>springloaded</artifactId>
                    <version>1.2.7.RELEASE</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <classifier>exec</classifier>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>

2、Run as ->Maven Build

3、运行,报错

java.lang.UnsupportedClassVersionError: com/learn/spring_boot_hello/App : Unsupported major.minor version 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Exception in thread "main" [INFO] ------------------------------------------------------------------------

4、打开Run Configuration

修改为JRE1.8
5、修改代码

6、刷新页面

7、这时候重新运行程序提示端口被占用,需要使用另外一种方法

在App内添加(需要实现创建lib目录,并把jar包拷贝进去,因为Maven jar包物理路径不在项目中)
-javaagent:.\lib\springloaded-1.2.7.RELEASE.jar -noverify

8、运行成功

总结:其实这种方法不是最简单的,使用JRebel要比这个好用,而且比较通用。

posted @ 2018-05-01 17:51  zhaogaojian  阅读(269)  评论(0编辑  收藏  举报