限制标记@RestOnMessage方法的条件
This commit is contained in:
@@ -239,6 +239,10 @@ public final class Rest {
|
||||
RestOnMessage rom = method.getAnnotation(RestOnMessage.class);
|
||||
if (rom == null) continue;
|
||||
String name = rom.name();
|
||||
if (Modifier.isFinal(method.getModifiers())) throw new RuntimeException("@RestOnMessage method can not final but (" + method + ")");
|
||||
if (Modifier.isStatic(method.getModifiers())) throw new RuntimeException("@RestOnMessage method can not static but (" + method + ")");
|
||||
if (method.getReturnType() != void.class) throw new RuntimeException("@RestOnMessage method must return void but (" + method + ")");
|
||||
if (method.getExceptionTypes().length > 0) throw new RuntimeException("@RestOnMessage method can not throw exception but (" + method + ")");
|
||||
if (name.isEmpty()) throw new RuntimeException(method + " RestOnMessage.name is empty createRestWebSocketServlet");
|
||||
if (messageNames.contains(name)) throw new RuntimeException(method + " repeat RestOnMessage.name(" + name + ") createRestWebSocketServlet");
|
||||
messageNames.add(name);
|
||||
|
||||
@@ -10,7 +10,12 @@ import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* 标记在RestWebSocket的接收消息方法上,方法通常是void返回类型
|
||||
* 标记在RestWebSocket的接收消息方法上; <br>
|
||||
* 注意:被标记的方法必须同时符合以下条件: <br>
|
||||
* 1、必须修饰为public
|
||||
* 2、不能修饰为final和static
|
||||
* 3、返回值必须是void
|
||||
* 4、不能throws检查型异常
|
||||
*
|
||||
* <br><p>
|
||||
* 详情见: https://redkale.org
|
||||
|
||||
Reference in New Issue
Block a user