NutzCN Logo
问答 为啥beetl的自定义标签不受nutz容器管理?
发布于 2275天前 作者 qq_64f81159 1331 次浏览 复制 上一个帖子 下一个帖子
标签:
@IocBean
public class DictTag extends GeneralVarTagBinding {
	String name,value,style,dictType;
	String type = "checkbox";
	StringBuffer sb = new StringBuffer();
	
	@Inject
	MacroService macroService;

	private void init() {
		name = (String)getAttributeValue("name");
		value = (String)getAttributeValue("value");
		style = (String)getAttributeValue("style");
		dictType = (String)getAttributeValue("dictType");
		type = (String)getAttributeValue("type");
	}

	@Override
	public void render() {
		init();
		List<Macro> list = macroService.listByDictType(dictType);
      }
}

这里会报空指针异常,没有找到marcoService ,而下面这样写就是对的

public class DictTag extends GeneralVarTagBinding {
	String name,value,style,dictType;
	String type = "checkbox";
	StringBuffer sb = new StringBuffer();
	MacroService macroService;

	private void init() {
		Ioc ioc = Mvcs.getIoc();
		name = (String)getAttributeValue("name");
		value = (String)getAttributeValue("value");
		style = (String)getAttributeValue("style");
		dictType = (String)getAttributeValue("dictType");
		type = (String)getAttributeValue("type");
		macroService = ioc.get(MacroService.class);
	}

	@Override
	public void render() {
		init();
		List<Macro> list = macroService.listByDictType(dictType);
       }
}
1 回复

ioc容器创建/管理的对象,才存在注入一说

配在beetl.properties的类,其实例是beetl自行new的,nutz ioc无法干预,也就没有注入

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