NutzCN Logo
问答 FreeMarkerConfigurer配置中{app: "$servlet"}获取异常
发布于 94天前 作者 七星爆珠 162 次浏览 复制 上一个帖子 下一个帖子
标签:
freeMarkerConfigurer: {
        type: "org.nutz.plugins.view.freemarker.FreeMarkerConfigurer",
        events: {
            create: 'init'
        },
        args: [
            {refer: "configuration"},
            {app: "$servlet"},
            "web/view",
            ".ftl",
            {refer: "freemarkerDirectiveFactory"}
        ]
    },

运行起来后,第一次初始化会产生如下异常

Caused by: org.nutz.castor.FailToCastObjectException: Fail to cast from <java.util.HashMap> to <javax.servlet.ServletContext> for {{app=$servlet}}
	at org.nutz.castor.Castors.cast(Castors.java:262)
	at org.nutz.castor.Castors.castTo(Castors.java:316)
	at org.nutz.lang.Lang.array2ObjectArray(Lang.java:1127)
	at org.nutz.lang.born.Borns.evalWithArgs(Borns.java:97)
	at org.nutz.lang.born.Borns.eval(Borns.java:58)
	at org.nutz.lang.Mirror.getBorning(Mirror.java:965)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:102)
	... 40 common frames omitted
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'javax.servlet.ServletContext'
 by args: []
 because: No suitable Constructor or Factory Method!!
	at org.nutz.lang.Mirror.born(Mirror.java:1008)
	at org.nutz.lang.Lang.map2Object(Lang.java:1173)
	at org.nutz.castor.castor.Map2Object.cast(Map2Object.java:14)
	at org.nutz.castor.castor.Map2Object.cast(Map2Object.java:9)
	at org.nutz.castor.Castors.cast(Castors.java:252)

16 回复

完整日志

18:53:15.485 DEBUG [o.n.i.i.NutIoc:165] - Get 'freeMarkerConfigurer'<class org.nutz.plugins.view.freemarker.FreeMarkerConfigurer>
18:53:15.485 DEBUG [o.n.i.i.NutIoc:191] - 	 >> Load definition name=freeMarkerConfigurer
18:53:15.485 DEBUG [o.n.i.l.c.ComboIocLoader:226] - Found IocObject(freeMarkerConfigurer) in JsonLoader(paths=[ioc/])
18:53:15.486 DEBUG [o.n.i.i.NutIoc:222] - 	 >> Make...'freeMarkerConfigurer'<class org.nutz.plugins.view.freemarker.FreeMarkerConfigurer>
18:53:15.486 DEBUG [o.n.i.i.ScopeContext:64] - Save object 'freeMarkerConfigurer' to [app] 
18:53:15.487 DEBUG [o.n.i.i.NutIoc:165] - Get 'configuration'<>
18:53:15.487 DEBUG [o.n.i.i.NutIoc:191] - 	 >> Load definition name=configuration
18:53:15.487 DEBUG [o.n.i.l.c.ComboIocLoader:226] - Found IocObject(configuration) in JsonLoader(paths=[ioc/])
18:53:15.487 DEBUG [o.n.i.i.NutIoc:222] - 	 >> Make...'configuration'<>
18:53:15.487 DEBUG [o.n.i.i.ScopeContext:64] - Save object 'configuration' to [app] 
18:53:15.501 DEBUG [o.n.i.a.i.DefaultMirrorFactory:76] - Load class freemarker.template.Configuration without AOP
18:53:15.651 DEBUG [o.n.i.i.NutIoc:165] - Get 'freemarkerDirectiveFactory'<>
18:53:15.652 DEBUG [o.n.i.i.NutIoc:191] - 	 >> Load definition name=freemarkerDirectiveFactory
18:53:15.652 DEBUG [o.n.i.l.c.ComboIocLoader:226] - Found IocObject(freemarkerDirectiveFactory) in JsonLoader(paths=[ioc/])
18:53:15.652 DEBUG [o.n.i.i.NutIoc:222] - 	 >> Make...'freemarkerDirectiveFactory'<>
18:53:15.652 DEBUG [o.n.i.i.ScopeContext:64] - Save object 'freemarkerDirectiveFactory' to [app] 
18:53:15.653 DEBUG [o.n.i.a.i.DefaultMirrorFactory:76] - Load class org.nutz.plugins.view.freemarker.FreemarkerDirectiveFactory without AOP
18:53:15.661 DEBUG [o.n.i.a.i.DefaultMirrorFactory:76] - Load class org.nutz.plugins.view.freemarker.FreeMarkerConfigurer without AOP
18:53:15.662 DEBUG [o.n.i.i.ScopeContext:84] - Remove object 'freeMarkerConfigurer' from [app] 
18:53:15.662 DEBUG [o.n.i.i.ScopeContext:84] - Remove object 'webHomeModule' from [app] 
18:53:15.664 WARN  [o.n.m.i.p.FailProcessor:28] - Error@/gameapi/s/alive :
org.nutz.ioc.IocException: IocBean[webHomeModule] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:270)
	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:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.nutz.mvc.WhaleFilter.doFilter(WhaleFilter.java:159)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: IocBean[webHomeModule] fail at field=[freeMarkerConfigurer]
	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)
	... 35 common frames omitted
Caused by: org.nutz.ioc.IocException: IocBean[freeMarkerConfigurer] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 37 common frames omitted
Caused by: org.nutz.castor.FailToCastObjectException: Fail to cast from <java.util.HashMap> to <javax.servlet.ServletContext> for {{app=$servlet}}
	at org.nutz.castor.Castors.cast(Castors.java:262)
	at org.nutz.castor.Castors.castTo(Castors.java:316)
	at org.nutz.lang.Lang.array2ObjectArray(Lang.java:1127)
	at org.nutz.lang.born.Borns.evalWithArgs(Borns.java:97)
	at org.nutz.lang.born.Borns.eval(Borns.java:58)
	at org.nutz.lang.Mirror.getBorning(Mirror.java:965)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:102)
	... 40 common frames omitted
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'javax.servlet.ServletContext'
 by args: []
 because: No suitable Constructor or Factory Method!!
	at org.nutz.lang.Mirror.born(Mirror.java:1008)
	at org.nutz.lang.Lang.map2Object(Lang.java:1173)
	at org.nutz.castor.castor.Map2Object.cast(Map2Object.java:14)
	at org.nutz.castor.castor.Map2Object.cast(Map2Object.java:9)
	at org.nutz.castor.Castors.cast(Castors.java:252)
	... 46 common frames omitted

main module贴一次看看

@Slf4j
@IocBean
@Views(value = {FreemarkerViewMaker.class})
@At("/s")
public class WebHomeModule {

但这个不是MainModule,我想这个Module有自己的View,所以配置了FreeMaker

@Views({CustomViewMaker.class})
@AdaptBy(type = CustomAdaptor.class)
@At("gameapi")
@Ok("_proto")
@Encoding(input = "UTF-8", output = "UTF-8")
public class MainModule {
}

这个是

没贴全吧?应该有IocBy

噢, 我试一下看看

试了一下并无报错, 你最初贴的ioc js配置,是自己加的???

配置文件实在https://github.com/nutzam/nutzmore/tree/master/nutz-plugins-views这里copy的

@Slf4j
@IocBean
@Views({FreemarkerViewMaker.class})
@At("/s")
public class WebHomeModule {
    @Inject
    private FreeMarkerConfigurer freeMarkerConfigurer;


js里去掉了,我希望在WebHomeModule 中引用Configurer对象,以便构建视图

new ViewWrapper(new FreemarkerView(freeMarkerConfigurer, "test"), null);

但是运行起来后会报出来这样的异常

19:32:56.169 WARN  [o.n.m.i.p.FailProcessor:28] - Error@/gameapi/s/alive :
org.nutz.ioc.IocException: IocBean[webHomeModule] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:270)
	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:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.nutz.mvc.WhaleFilter.doFilter(WhaleFilter.java:159)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: IocBean[webHomeModule] fail at field=[freeMarkerConfigurer]
	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)
	... 35 common frames omitted
Caused by: org.nutz.ioc.IocException: IocBean[freeMarkerConfigurer] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 37 common frames omitted
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'org.nutz.boot.starter.freemarker.FreeMarkerConfigurer'because: java.lang.NullPointerException
	at org.nutz.lang.born.EmptyArgsConstructorBorning.born(EmptyArgsConstructorBorning.java:17)
	at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:78)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:117)
	... 40 common frames omitted
Caused by: java.lang.NullPointerException: null
	at org.nutz.boot.starter.freemarker.FreeMarkerConfigurer.initp(FreeMarkerConfigurer.java:45)
	at org.nutz.boot.starter.freemarker.FreeMarkerConfigurer.<init>(FreeMarkerConfigurer.java:38)
	at org.nutz.boot.starter.freemarker.FreeMarkerConfigurer$FC$62febe830a4a6764c634d9e263964cee.invoke(FreeMarkerConfigurer.java)
	at org.nutz.lang.born.AbstractConstructorBorning.call(AbstractConstructorBorning.java:25)
	at org.nutz.lang.born.EmptyArgsConstructorBorning.born(EmptyArgsConstructorBorning.java:14)
	... 42 common frames omitted

把demo跑起来

只需要加个starter依赖, 其他js/类,统统不需要加的...

搞定了 ,自己眼花了, 因为用了starter同时还引用了plugins-view里面的configurer,传入的对象名字又一样~~~
最后解决方法:
1.用start即可,js不需要配置
2.依赖引用只配置starter即可,引入plugins-view会导致混淆,没有编译错误,但是容易错乱

是的@wendal,已解决,多谢~

添加回复
请先登陆
回到顶部