我想利用 nutzboot加 MainModule实现原mvc方式的ioc注入,其实就是想利用原来mvc的js配置来实现灵活的自定义规则集。
var ioc = {
rule_conf : {
type : "com.smart.station.rule.impl.MyPropertiesProxy",
events : {
create : "create",
depose : "depose"
},
args : ["rule/"]
},
rule_test1 : {
type : "com.smart.station.rule.impl.TestRuleImpl",
fields : {
rule_name: "test1规则",
rule_descp: {java:"rule_conf.get('rule.descrp')"},
expireMs: 5000,
cnd_list : [
{refer: "cnd_test1"},
]
},
events : {
create : "create",
depose : "depose"
},
},
rule_test2 : {
type : "com.smart.station.rule.impl.TestRuleImpl",
fields : {
rule_name: "test2规则",
rule_descp: "test2规则描述",
expireMs: 5000,
cnd_list : [
{refer: "cnd_test1"},
]
},
events : {
create : "create",
depose : "depose"
},
},
};
//@SetupBy(value=MainSetup.class)
@IocBy(type=ComboIocProvider.class, args={"*js", "ioc/",
// "*anno", "com.server.main",
// "*tx", "*org.nutz.integration.quartz.QuartzIocLoader"
})
//@Modules(scanPackage=true) //将自动搜索主模块所在的包(包括子包)下所有的类,如果有类包括了一个以上的 入口函数将被认为是模块类
//@Localization(value="msg/", defaultLocalizationKey="zh-CN")
public class MainModule {
}
@Slf4j
public class MyPropertiesProxy extends PropertiesProxy {
public MyPropertiesProxy(String... paths) {
super(true);
this.setPaths(paths);
}
public synchronized void create(){
log.info("MyPropertiesProxy - create()");
}
public synchronized void depose() {
log.info("MyPropertiesProxy - depose()");
}
}
启动类
public static void main(String[] args) throws Exception {
// new NbApp(MainModule.class).setArgs(args).setPrintProcDoc(true).run();
new NbApp(MainModule.class).setArgs(args).setPrintProcDoc(true).run();
}
以前mvc方式 这个 rule_conf会由于rule_test1而被自动注入,但是nutzboot 却不能,导致异常:
org.nutz.ioc.IocException: IocBean[testModule] throw Exception when creating
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:153)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:56)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:124)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at org.nutz.mvc.WhaleFilter.doFilter(WhaleFilter.java:171)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:65)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:336)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: IocBean[testModule] fail at field=[test_rule1]
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
... 37 more
Caused by: org.nutz.ioc.IocException: IocBean[rule_test1] throw Exception when creating
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:153)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
... 39 more
Caused by: java.lang.RuntimeException: Fail to eval Injector for field: 'rule_descp'
at org.nutz.lang.Lang.wrapThrow(Lang.java:174)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:131)
... 42 more
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: rule_conf
at org.nutz.lang.Lang.wrapThrow(Lang.java:191)
at org.nutz.ioc.java.StaticFunctionNode.<init>(StaticFunctionNode.java:57)
at org.nutz.ioc.java.ChainParsing.parse(ChainParsing.java:107)
at org.nutz.ioc.java.ChainParsing.<init>(ChainParsing.java:33)
at org.nutz.ioc.val.JavaValue.<init>(JavaValue.java:64)
at org.nutz.ioc.impl.DefaultValueProxyMaker.make(DefaultValueProxyMaker.java:89)
at org.nutz.ioc.IocMaking.makeValue(IocMaking.java:75)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:127)
... 42 more
Caused by: java.lang.ClassNotFoundException: rule_conf
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.nutz.lang.Lang.loadClass(Lang.java:2090)
at org.nutz.ioc.java.StaticFunctionNode.<init>(StaticFunctionNode.java:26)
... 48 more
我看了下《将普通JavaEE项目转变为NutzBoot的项目》说
“通常来说,原项目会有dao.js或dao.json或者db.js, 里面有conf对象,我们需要将它的定义删除”
意思是这些js在nutzboot环境下不能使用 conf来配置吗? 只能在js中直接写值?