NutzCN Logo
问答 nutz filter 获取ioc注入对象失败
发布于 344天前 作者 Wordsdonotread 402 次浏览 复制 上一个帖子 下一个帖子
标签:
import cn.com.cy.authclient.Assertion;
import cn.com.cy.authclient.AuthClient;
import cn.com.cy.authclient.AuthUser;
public View match(ActionContext actionContext) {
		//统一认证用户权限验证
		try {
			AuthClient authClient = actionContext.getIoc().get(AuthClient.class, "authClient");
			Assertion assertion = authClient.login(Mvcs.getReq(), Mvcs.getResp(),"");
			if(assertion != null){
				AuthUser authUser = assertion.getAuthUser();
				if( !authUser.getCookieId().equals(token));{
					return new JsonView(Restful.instance(false,
							"header token not equal to Auth token",
							null, 450));
				}
			}
		} catch (Exception e1) {
			LOG.error(e1.getMessage(), e1);
			e1.printStackTrace();
			return new JsonView(Restful.instance(false, e1.getMessage(), e1, 500));
		}
		return null;
}
var ioc = {
	authClient :{
      	        type : "cn.com.cy.authclient.AuthClient",
		args : [ "http://192.168.0.152:8080/ssoserver/","www","qq1"]
	}
}
报下面错误。
org.nutz.ioc.IocException: [authClient] # For object [authClient] - type:[class
cn.com.cy.authclient.AuthClient]
        at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
        at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
        at cn.com.infcn.mss.filter.TokenFilter.match(TokenFilter.java:86)
        at org.nlpcn.jcoder.run.mvc.processor.ApiActionFiltersProcessor.process(
ApiActionFiltersProcessor.java:59)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nlpcn.jcoder.run.mvc.processor.ApiModuleProcessor.process(ApiModu
leProcessor.java:35)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nlpcn.jcoder.run.mvc.processor.ApiCrossOriginProcessor.process(Ap
iCrossOriginProcessor.java:35)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcess
or.java:27)
        at org.nlpcn.jcoder.run.mvc.JcoderActionChain.doChain(JcoderActionChain.
java:52)
        at org.nlpcn.jcoder.run.mvc.processor.ApiActionInvoker.invoke(ApiActionI
nvoker.java:36)
        at org.nlpcn.jcoder.run.mvc.ApiActionHandler.handle(ApiActionHandler.jav
a:38)
        at org.nlpcn.jcoder.filter.JcoderFilter._doFilter(JcoderFilter.java:80)
        at org.nlpcn.jcoder.filter.JcoderFilter.doFilter(JcoderFilter.java:44)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(Servlet
Handler.java:1650)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java
:583)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.j
ava:143)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.jav
a:577)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandl
er.java:223)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandl
er.java:1125)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:
515)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandle
r.java:185)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandle
r.java:1059)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.j
ava:141)
        at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:
52)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper
.java:97)
        at org.eclipse.jetty.server.Server.handle(Server.java:485)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:290)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.jav
a:248)
        at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java
:540)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPoo
l.java:606)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool
.java:535)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.nutz.ioc.ObjectLoadException: Object 'authClient' without define!

        at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:174
)
        at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
        ... 33 more

6 回复

@Filters写了什么

@Filters(@By(type = TokenFilter.class, args={"false"}))

报错信息没贴全,没看到实际报错原因

我的ioc管理里面有个authClient的一个注入对象,配置文件如下
var ioc = {
	authClient :{
      	        type : "cn.com.cy.authclient.AuthClient",
		args : [ "http://192.168.0.152:8080/ssoserver/","www","qq1"]
	}
}
然后想从filter当中获取authClient
AuthClient authClient = actionContext.getIoc().get(AuthClient.class, "authClient");
在filter执行上面一行代码的时候,就报
Caused by: org.nutz.ioc.ObjectLoadException: Object 'authClient' without define!

        at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:174)
        at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
        ... 33 more

我这边能显示的错误日志只有这些了。

[cn.com.infcn.mss.filter.TokenFilter@65f2e03b]
cn.com.infcn.mss.filter.TokenFilter-213438 ERROR [2019-09-05 14:02:58]  [authCli
ent] # For object [authClient] - type:[class cn.com.cy.authclient.AuthClient]
org.nutz.ioc.IocException: [authClient] # For object [authClient] - type:[class
cn.com.cy.authclient.AuthClient]
        at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218) ~[nutz-1.r.58.jar:?]
        at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239) ~[nutz-1.r.58.jar:?]
        at cn.com.infcn.mss.filter.TokenFilter.match(TokenFilter.java:86) [msp-a
pi-0.8.jar:?]
        at org.nlpcn.jcoder.run.mvc.processor.ApiActionFiltersProcessor.process(
ApiActionFiltersProcessor.java:59) [jcoder-3.1.6.jar:?]
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44) [nutz-1.r.58.jar:?]
        at org.nlpcn.jcoder.run.mvc.processor.ApiModuleProcessor.process(ApiModu
leProcessor.java:35) [jcoder-3.1.6.jar:?]
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44) [nutz-1.r.58.jar:?]
        at org.nlpcn.jcoder.run.mvc.processor.ApiCrossOriginProcessor.process(Ap
iCrossOriginProcessor.java:35) [jcoder-3.1.6.jar:?]
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44) [nutz-1.r.58.jar:?]
        at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcess
or.java:27) [nutz-1.r.58.jar:?]
        at org.nlpcn.jcoder.run.mvc.JcoderActionChain.doChain(JcoderActionChain.
java:52) [jcoder-3.1.6.jar:?]
        at org.nlpcn.jcoder.run.mvc.processor.ApiActionInvoker.invoke(ApiActionI
nvoker.java:36) [jcoder-3.1.6.jar:?]
        at org.nlpcn.jcoder.run.mvc.ApiActionHandler.handle(ApiActionHandler.jav
a:38) [jcoder-3.1.6.jar:?]
        at org.nlpcn.jcoder.filter.JcoderFilter._doFilter(JcoderFilter.java:80)
[jcoder-3.1.6.jar:?]
        at org.nlpcn.jcoder.filter.JcoderFilter.doFilter(JcoderFilter.java:44) [
jcoder-3.1.6.jar:?]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(Servlet
Handler.java:1650) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java
:583) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.j
ava:143) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.jav
a:577) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandl
er.java:223) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandl
er.java:1125) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:
515) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandle
r.java:185) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandle
r.java:1059) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.j
ava:141) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:
52) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper
.java:97) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.server.Server.handle(Server.java:485) [jcoder-3.1.6
.war:3.1.6]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:290) [jc
oder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.jav
a:248) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java
:540) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPoo
l.java:606) [jcoder-3.1.6.war:3.1.6]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool
.java:535) [jcoder-3.1.6.war:3.1.6]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151]
Caused by: org.nutz.ioc.ObjectLoadException: Object 'authClient' without define!

        at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:174
) ~[nutz-1.r.58.jar:?]
        at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180) ~[nutz-1.r.58.jar:?]
        ... 33 more
org.nutz.ioc.IocException: [authClient] # For object [authClient] - type:[class
cn.com.cy.authclient.AuthClient]
        at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
        at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
        at cn.com.infcn.mss.filter.TokenFilter.match(TokenFilter.java:86)
        at org.nlpcn.jcoder.run.mvc.processor.ApiActionFiltersProcessor.process(
ApiActionFiltersProcessor.java:59)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nlpcn.jcoder.run.mvc.processor.ApiModuleProcessor.process(ApiModu
leProcessor.java:35)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nlpcn.jcoder.run.mvc.processor.ApiCrossOriginProcessor.process(Ap
iCrossOriginProcessor.java:35)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcess
or.java:27)
        at org.nlpcn.jcoder.run.mvc.JcoderActionChain.doChain(JcoderActionChain.
java:52)
        at org.nlpcn.jcoder.run.mvc.processor.ApiActionInvoker.invoke(ApiActionI
nvoker.java:36)
        at org.nlpcn.jcoder.run.mvc.ApiActionHandler.handle(ApiActionHandler.jav
a:38)
        at org.nlpcn.jcoder.filter.JcoderFilter._doFilter(JcoderFilter.java:80)
        at org.nlpcn.jcoder.filter.JcoderFilter.doFilter(JcoderFilter.java:44)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(Servlet
Handler.java:1650)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java
:583)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.j
ava:143)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.jav
a:577)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandl
er.java:223)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandl
er.java:1125)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:
515)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandle
r.java:185)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandle
r.java:1059)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.j
ava:141)
        at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:
52)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper
.java:97)
        at org.eclipse.jetty.server.Server.handle(Server.java:485)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:290)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.jav
a:248)
        at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java
:540)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPoo
l.java:606)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool
.java:535)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.nutz.ioc.ObjectLoadException: Object 'authClient' without define!

        at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:174
)
        at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
        ... 33 more

Object 'authClient' without define!

声明这个authClient没被加载

用注解就好啦,何必写个ioc js文件

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