# groovy-script-example_1 **Repository Path**: feifei2019/groovy-script-example_1 ## Basic Information - **Project Name**: groovy-script-example_1 - **Description**: No description available - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-02-05 - **Last Updated**: 2024-02-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### springboot接口动态执行groovy脚本 > 展示如何通过动态groovy脚本直接调用spring context中注册的bean的方法,方便项目测试,但正式项目中请对脚本运行接口做好权限控制 1. 打包:项目根目录运行: mvn clean install ,在target目录下生产可执行jar包:groovy-script-example-1.0.0.jar 2. 运行: 以jar包所在目录运行为例: java -jar groovy-script-example-1.0.0.jar, 默认使用8080端口(可自行修改springboot配置文件定义端口号) 3. 脚本执行: + url: [http://${ip}:8080/groovy/script/execute](http://localhost:8080/groovy/script/execute) + method: post + bodytype: Text + body: groovy脚本 4. 示例groovy脚本: + 调用TestService方法: ``` def query = testService.testQuery(1L) query ``` 结果返回:"Test query success, id is 1". + 直接调用scriptBaseClass的方法: ``` def sum = add(1,2) sum ``` 结果返回: 3.