匿名函数托管器 spring-boot-func-starter
spring-boot-func-starter
spring-boot-func-starter 介绍
项目地址: //gitee.com/yiur/spring-boot-func-starter
基于SpringBoot的匿名函数托管器,在springboot中可以将接口的方法进行各种操作
平时的java开发中继承接口要将接口的方法全实现,而func匿名函数托管不需要进行全部
实现可以用@FuncLambda
进行单独实现,没有进行匿名实现的接口方法不能进行调用,
func匿名函数还可以动态实现接口方法,配合代码达到更多操作,此外还有函数回调的
功能,在web开发中使用func匿名函数的对象是默认调用回调方法的,你也可以通过继承
Callback
接口编写自己想要的(then, error)回调方法
error
目前不兼容springboot的热部署
@FuncConfiguration
匿名配置
@FuncLambda
匿名函数配置
注解模式开发
项目搭建
定义接口,此接口的方法由匿名函数代理
public interface WebInitOutInfo {
String out(String message, String... args);
}
@FuncConfiguration
匿名函数的总配置@FuncLambda
匿名函数classFile
代理的接口funcCallback
回调函数callbackClass
绑定的回调函数类
@FuncConfiguration
public class WebFuncLinkConfig {
@FuncLambda(classFile = WebInitOutInfo.class,
funcCallback = @FuncCallback(callbackClass = BlogCallback.class))
public String out(@FuncParameter("message") String message, @FuncParameter("args") String... args) {
return FuncString.format(message, args);
}
}
回调函数实现Callback
接口即可
public class BlogCallback implements Callback {
@Override
public Object then(Object o) {
return FuncString.format("then blogCallBack:value(?)", o);
}
@Override
public Object error(Exception e) {
return ((InvocationTargetException)e).getTargetException().getMessage();
}
}
启动类开启匿名函数自动装配 @EnableFuncLambda
@EnableWebMvc
@EnableFuncLambda
@SpringBootApplication
public class WebBlogApplication {
public static void main(String[] args) {
SpringApplication.run(WebBlogApplication.class, args);
}
}
配置web进行测试,编写controller
@Controller
public class BlogController {
@Autowired
public WebInitOutInfo webInitOutInfo;
@ResponseBody
@RequestMapping("/replace")
public String value(String message, String... args) {
return webInitOutInfo.out(message, args);
}
}
测试成功回调[//localhost:8888/replace?message=value ? ?&args=12, hello func](//localhost:8888/replace?message=value ? ?&args=12, hello func)
测试失败回调[//localhost:8888/replace?message=value ? ??&args=12,%20hello%20func](//localhost:8888/replace?message=value ? ??&args=12, hello func)