java服务可以断开交换机系统,手动降级服务并停止服务。 基于spring AOP机制,支持在特殊情况下屏蔽某些相关服务类的返回,定义默认返回结果,并随机屏蔽某些异常服务。 启动内置的http服务器以接收外部命令。
对当前APP应用程序的影响。 有关代码,请参见https://github.com/zhwj 184/auto switch
使用指南:
将以下内容添加到spring配置文件中: 其中,switch-service-pointcut是紧急情况下需要屏蔽的方法列表
org.autoswitch.test.*
例如,下一个服务。 每次启动APP应用程序后,都手动屏蔽服务调用,然后调用直接使用参数的jsonResult反序列时返回上面的注释。 classmethod是一个具体的方法名称,status表示将关闭服务以进行open,close表示将重新打开服务,jsonResult是mock返回结果的json字符串。对于基本类型,则不使用ret作为密钥其他list、bean等直接使用json字符串。 type表示list是一个类完整类型,如果具有通用性,则返回该类型。
publicclasstestserviceimplimplementstestservice {
//http://localhost :8080/control/a.htm? class method=org.auto switch.test.testserviceimpl.hello status=open JSON result=1
公共语音助手() {
system.out.println(Hello );
}
//http://localhost :8080/control/a.htm? class method=org.auto switch.test.testserviceimpl.say hello status=open JSON result={ ret : " god buy " }
公共字符串say hello () {
返回' say hello ';
}
//http://localhost :8080/control/a.htm? class method=org.auto switch.test.testserviceimpl.getnamesstatus=open JSON result=[ { ' catlist ' : ] ' id ' 3333330
公共列表getnames
返回空值;
}
//http://localhost :8080/control/a.htm? class method=org.auto switch.test.testserviceimpl.getbeansstatus=open JSON result={ ' catlist ' : [ ' 123 ',]
3调用示例代码
公共类管理{
publicstaticvoidmain (字符串[ ] args ) {
classpathxmlapplicationcontextcontext=newclasspathxmlapplicationcontext (' class path * : spring-bean.XML ' );
testservicetestcontrol=(testservice ) context.getbean('testservice );
try{
testControl.hello (;
系统. out.println (test control.say hello ();
List list=testControl.getNames (;
for(Testbeanbean:list ) {
system.out.println(bean.getid ) (bean.getName ) (bean.getCatList ) );
}
testbean bean=test control.get beans (;
system.out.println(bean.getid ) (bean.getName ) (bean.getCatList ) );
}catch(exceptione ) }
for(intI=0; i 10; I ) {
try{
//testControl.hello (;
系统. out.println (test control.say hello ();
//list list=test control.getnames (;
//for(Testbeanbean:list ) {
//system.out.println (bean.getid ) (bean.getName ) (bean.getCatList ) );
//}
//testbean bean=test control.get beans (;
//system.out.println (bean.getid ) (bean.getName ) (bean.getCatList ) );
}catch(exceptione ) {
e .打印堆栈跟踪(;
}
}
}
}
4 .输出
端口侦听程序8080
你好
sayHello
incomingconnectionfrom/127.0.0.1
新建连接线程
好的拜拜
好的拜拜
incomingconnectionfrom/127.0.0.1
新建连接线程
sayHello
sayHello
sayHello
sayHello
sayHello
sayHello
sayHello
sayHello
此处仅提供了一个示例,在生产环境中使用时,需要控制并发控制、返回结果的序列化、方法名称匹配参数不匹配等各种情况,同时还需要优化权限、后台管理系统等。