兼容手动new XXXService字段inject时抛异常
This commit is contained in:
@@ -240,7 +240,11 @@ public abstract class NodeServer {
|
|||||||
}
|
}
|
||||||
if (DataSource.class.isAssignableFrom(sourceType) && can) { // 必须有空构造函数
|
if (DataSource.class.isAssignableFrom(sourceType) && can) { // 必须有空构造函数
|
||||||
final Service srcService = (Service) src;
|
final Service srcService = (Service) src;
|
||||||
SncpClient client = Sncp.getSncpClient(srcService);
|
SncpClient client = null;
|
||||||
|
try {
|
||||||
|
client = Sncp.getSncpClient(srcService);
|
||||||
|
} catch (RuntimeException re) {
|
||||||
|
}
|
||||||
final InetSocketAddress sncpAddr = client == null ? null : client.getClientAddress();
|
final InetSocketAddress sncpAddr = client == null ? null : client.getClientAddress();
|
||||||
final Set<String> groups = new HashSet<>();
|
final Set<String> groups = new HashSet<>();
|
||||||
if (client != null && client.getSameGroup() != null) groups.add(client.getSameGroup());
|
if (client != null && client.getSameGroup() != null) groups.add(client.getSameGroup());
|
||||||
@@ -255,7 +259,11 @@ public abstract class NodeServer {
|
|||||||
application.dataSources.add(source);
|
application.dataSources.add(source);
|
||||||
appResFactory.register(resourceName, DataSource.class, source);
|
appResFactory.register(resourceName, DataSource.class, source);
|
||||||
|
|
||||||
SncpClient client = Sncp.getSncpClient((Service) src);
|
SncpClient client = null;
|
||||||
|
try { //Service成员变量是一个直接new XXXService的字段, 递归ResourceFactory.inject时会导致找不到SncpClient
|
||||||
|
client = Sncp.getSncpClient((Service) src);
|
||||||
|
} catch (RuntimeException re) {
|
||||||
|
}
|
||||||
final InetSocketAddress sncpAddr = client == null ? null : client.getClientAddress();
|
final InetSocketAddress sncpAddr = client == null ? null : client.getClientAddress();
|
||||||
if ((src instanceof DataSource) && sncpAddr != null && resourceFactory.find(resourceName, DataCacheListener.class) == null) { //只有DataSourceService 才能赋值 DataCacheListener
|
if ((src instanceof DataSource) && sncpAddr != null && resourceFactory.find(resourceName, DataCacheListener.class) == null) { //只有DataSourceService 才能赋值 DataCacheListener
|
||||||
final NodeSncpServer sncpServer = application.findNodeSncpServer(sncpAddr);
|
final NodeSncpServer sncpServer = application.findNodeSncpServer(sncpAddr);
|
||||||
|
|||||||
Reference in New Issue
Block a user