# runtime-development-demo **Repository Path**: daiyunlai/runtime-development-demo ## Basic Information - **Project Name**: runtime-development-demo - **Description**: 这是一个java在线开发controller接口并发布的demo - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-05-30 - **Last Updated**: 2023-05-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README **这是一个java在线开发并发布的demo** 可以在线编写controller代码,点击发布后就可以调用接口了。 **实现方式** 1. 页面写controller代码。点击发布 2. 使用JavaCompiler编译String类型的java代码 3. 使用ClassLoader加载类,得到Class对象 4. 将class注册到DefaultListableBeanFactory中 5. 向RequestMappingHandlerMapping中注册controller 6. 截至当前,已经可以正常访问这个controller接口了 **介绍** 就是一个普通的springboot项目.启动后访问http://localhost:8080/端口就能打开页面了,长这样 ![img_1.png](img_1.png) **点击发布按钮会将页面上写的这个controller动态注册到运行时容器里。发布完就可以访问调用了** ![img_2.png](img_2.png) **缺陷** 页面写的代码会编译成class文件,放在target/classes/${package}目录下,项目重启后就会直接加载到这个class文件。