@Resource支持含{system.property.xxx}模式
This commit is contained in:
@@ -169,19 +169,6 @@ public final class Rest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getRestWebSocketResourceName(String name) {
|
|
||||||
if (name == null) return null;
|
|
||||||
int pos = name.indexOf("{system.property.");
|
|
||||||
if (pos < 0) return name;
|
|
||||||
String prefix = name.substring(0, pos);
|
|
||||||
String subname = name.substring(pos + "{system.property.".length());
|
|
||||||
pos = subname.indexOf('}');
|
|
||||||
if (pos < 0) return name;
|
|
||||||
String postfix = subname.substring(pos + 1);
|
|
||||||
String property = subname.substring(0, pos);
|
|
||||||
return getRestWebSocketResourceName(prefix + System.getProperty(property, "") + postfix);
|
|
||||||
}
|
|
||||||
|
|
||||||
static <T extends HttpServlet> T createRestWebSocketServlet(final ClassLoader classLoader, final Class<? extends WebSocket> webSocketType) {
|
static <T extends HttpServlet> T createRestWebSocketServlet(final ClassLoader classLoader, final Class<? extends WebSocket> webSocketType) {
|
||||||
if (webSocketType == null) throw new RuntimeException("Rest WebSocket Class is null on createRestWebSocketServlet");
|
if (webSocketType == null) throw new RuntimeException("Rest WebSocket Class is null on createRestWebSocketServlet");
|
||||||
if (Modifier.isAbstract(webSocketType.getModifiers())) throw new RuntimeException("Rest WebSocket Class(" + webSocketType + ") cannot abstract on createRestWebSocketServlet");
|
if (Modifier.isAbstract(webSocketType.getModifiers())) throw new RuntimeException("Rest WebSocket Class(" + webSocketType + ") cannot abstract on createRestWebSocketServlet");
|
||||||
@@ -196,7 +183,7 @@ public final class Rest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!valid) throw new RuntimeException("Rest WebSocket Class(" + webSocketType + ") must have public or protected Constructor on createRestWebSocketServlet");
|
if (!valid) throw new RuntimeException("Rest WebSocket Class(" + webSocketType + ") must have public or protected Constructor on createRestWebSocketServlet");
|
||||||
final String rwsname = getRestWebSocketResourceName(rws.name());
|
final String rwsname = ResourceFactory.formatResourceName(rws.name());
|
||||||
if (!checkName(rws.catalog())) throw new RuntimeException(webSocketType.getName() + " have illeal " + RestWebSocket.class.getSimpleName() + ".catalog, only 0-9 a-z A-Z _ cannot begin 0-9");
|
if (!checkName(rws.catalog())) throw new RuntimeException(webSocketType.getName() + " have illeal " + RestWebSocket.class.getSimpleName() + ".catalog, only 0-9 a-z A-Z _ cannot begin 0-9");
|
||||||
if (!checkName(rwsname)) throw new RuntimeException(webSocketType.getName() + " have illeal " + RestWebSocket.class.getSimpleName() + ".name, only 0-9 a-z A-Z _ cannot begin 0-9");
|
if (!checkName(rwsname)) throw new RuntimeException(webSocketType.getName() + " have illeal " + RestWebSocket.class.getSimpleName() + ".name, only 0-9 a-z A-Z _ cannot begin 0-9");
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||||||
/**
|
/**
|
||||||
* 只能依附在WebSocket类上,name默认为Service的类名小写并去掉Service字样及后面的字符串 (如HelloWebSocket/HelloWebSocketImpl,的默认路径为 hello)。 <br>
|
* 只能依附在WebSocket类上,name默认为Service的类名小写并去掉Service字样及后面的字符串 (如HelloWebSocket/HelloWebSocketImpl,的默认路径为 hello)。 <br>
|
||||||
* <b>注意: </b> 被标记@RestWebSocket的WebSocket不能被修饰为abstract或final,且其内部标记为@Resource的字段只能是protected或public,且必须要有一个protected或public的空参数构造函数。 <br>
|
* <b>注意: </b> 被标记@RestWebSocket的WebSocket不能被修饰为abstract或final,且其内部标记为@Resource的字段只能是protected或public,且必须要有一个protected或public的空参数构造函数。 <br>
|
||||||
|
* name值支持含{system.property.xxx}模式
|
||||||
* <p>
|
* <p>
|
||||||
* 详情见: https://redkale.org
|
* 详情见: https://redkale.org
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -532,6 +532,19 @@ public final class ResourceFactory {
|
|||||||
return inject(src, attachment, consumer, new ArrayList());
|
return inject(src, attachment, consumer, new ArrayList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String formatResourceName(String name) {
|
||||||
|
if (name == null) return null;
|
||||||
|
int pos = name.indexOf("{system.property.");
|
||||||
|
if (pos < 0) return name;
|
||||||
|
String prefix = name.substring(0, pos);
|
||||||
|
String subname = name.substring(pos + "{system.property.".length());
|
||||||
|
pos = subname.indexOf('}');
|
||||||
|
if (pos < 0) return name;
|
||||||
|
String postfix = subname.substring(pos + 1);
|
||||||
|
String property = subname.substring(0, pos);
|
||||||
|
return formatResourceName(prefix + System.getProperty(property, "") + postfix);
|
||||||
|
}
|
||||||
|
|
||||||
private <T> boolean inject(final Object src, final T attachment, final BiConsumer<Object, Field> consumer, final List<Object> list) {
|
private <T> boolean inject(final Object src, final T attachment, final BiConsumer<Object, Field> consumer, final List<Object> list) {
|
||||||
if (src == null) return false;
|
if (src == null) return false;
|
||||||
try {
|
try {
|
||||||
@@ -575,7 +588,7 @@ public final class ResourceFactory {
|
|||||||
|
|
||||||
}
|
}
|
||||||
boolean autoregnull = true;
|
boolean autoregnull = true;
|
||||||
final String rcname = tname;
|
final String rcname = formatResourceName(tname);
|
||||||
Object rs;
|
Object rs;
|
||||||
if (rcname.startsWith("system.property.")) {
|
if (rcname.startsWith("system.property.")) {
|
||||||
rs = System.getProperty(rcname.substring("system.property.".length()));
|
rs = System.getProperty(rcname.substring("system.property.".length()));
|
||||||
|
|||||||
Reference in New Issue
Block a user