NutzCN Logo
问答 Map类型的Bean属性如何引用
发布于 2303天前 作者 Tomcat 1885 次浏览 复制 上一个帖子 下一个帖子
标签:

在IoC中定义给shiroFilter的filters属性(Map<String, Filter>类型)注入java调用会失败:

  "shiroFilter": {
    "type": "nvc.web.ShiroFilterImpl",
    "fields": {
      "securityManager": {
        "refer": "shiroSecurityManager"
      },
      "loginUrl": {
        "java": "$config.get('nvc.shiro.login_url')"
      },
      "successUrl": {
        "java": "$config.get('nvc.shiro.success_url')"
      },
      "filters": {
        "java": "$mapper.toMap($config.get('nvc.shiro.filters').split(','))"
      },
      "chainDefinitions": {
        "java": "$config.get('nvc.shiro.filter_chain').split('\\n')"
      }

给出的是异常:

org.nutz.ioc.IocException: IocBean[shiroFilter] throw Exception when creating
	org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	nvc.web.NutFilterDelegate.internalInit(NutFilterDelegate.java:37)
	nvc.web.NutFilterDelegate.doFilter(NutFilterDelegate.java:31)

root cause

java.lang.RuntimeException: IocBean[shiroFilter] fail at field=[filters]
	org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	nvc.web.NutFilterDelegate.internalInit(NutFilterDelegate.java:37)
	nvc.web.NutFilterDelegate.doFilter(NutFilterDelegate.java:31)

root cause

java.lang.NullPointerException
	org.nutz.ioc.java.FieldNode.getValue(FieldNode.java:15)
	org.nutz.ioc.java.ObjectFunctionNode.getValue(ObjectFunctionNode.java:22)
	org.nutz.ioc.java.ChainNode.eval(ChainNode.java:24)
	org.nutz.ioc.java.ChainNode.eval(ChainNode.java:27)
	org.nutz.ioc.java.ChainNode.eval(ChainNode.java:19)
	org.nutz.ioc.val.JavaValue.get(JavaValue.java:69)
	org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	nvc.web.NutFilterDelegate.internalInit(NutFilterDelegate.java:37)
	nvc.web.NutFilterDelegate.doFilter(NutFilterDelegate.java:31)

5 回复

试试用el

      "filters": {
        "el": "$mapper.toMap($config.get('nvc.shiro.filters').split(','))"
      },

用el仍然一样。另外值改了个随便什么字符串(例如"el": "abcdef"),结果也不变。

注入PropertiesProxy,在代码里面取吧

对哦,这个ShiroFilter是在同一个项目里实现的……

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