This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
package org.redkale.boot;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.*;
|
||||
@@ -15,13 +15,14 @@ import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import java.util.logging.*;
|
||||
import javax.annotation.Resource;
|
||||
import javax.xml.parsers.*;
|
||||
import org.redkale.boot.ClassFilter.FilterEntry;
|
||||
import org.redkale.convert.bson.BsonFactory;
|
||||
import org.redkale.convert.json.JsonFactory;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.net.http.MimeType;
|
||||
import org.redkale.net.sncp.SncpClient;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
@@ -359,6 +360,24 @@ public final class Application {
|
||||
this.resourceFactory.register(JsonFactory.root());
|
||||
this.resourceFactory.register(BsonFactory.root().getConvert());
|
||||
this.resourceFactory.register(JsonFactory.root().getConvert());
|
||||
//只有WatchService才能加载Application、WatchFactory
|
||||
final Application application = this;
|
||||
this.resourceFactory.register((ResourceFactory rf, final Object src, String resourceName, Field field, final Object attachment) -> {
|
||||
try {
|
||||
Resource res = field.getAnnotation(Resource.class);
|
||||
if (res == null || !res.name().isEmpty()) return;
|
||||
if (!(src instanceof WatchService) || Sncp.isRemote((Service) src)) return; //远程模式不得注入
|
||||
Class type = field.getType();
|
||||
if (type == Application.class) {
|
||||
field.set(src, application);
|
||||
} else if (type == WatchFactory.class) {
|
||||
field.set(src, application.watchFactory);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Resource inject error", e);
|
||||
}
|
||||
}, Application.class, WatchFactory.class);
|
||||
//--------------------------------------------------------------------------
|
||||
initResources();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.redkale.watch;
|
||||
import org.redkale.service.*;
|
||||
|
||||
/**
|
||||
* 只给WATCH协议的Server才能加载的Service,其他协议的Server均不能自动加载WatchService
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user