NutzCN Logo
问答 集成rabbitmq问题
发布于 2089天前 作者 yahtob 2231 次浏览 复制 上一个帖子 下一个帖子
标签:

channel()报空指针

package com.hits.modules.rabbitmq;

import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.IocBean;

import static org.nutz.integration.rabbitmq.aop.RabbitmqMethodInterceptor.channel;


@IocBean
public class SendMqService {
    @Aop("rabbitmq") // 会自动管理Connection/Channel的开启和关闭.
    public void publish(String routingKey, byte[] body) throws Exception {
        channel().basicPublish("", routingKey, null, body);

    }
}

java.lang.NullPointerException
	at com.demo.rabbitmq.SendMqService.publish(SendMqService.java:13)
11 回复
import static org.nutz.integration.rabbitmq.aop.RabbitmqMethodInterceptor.*;

通常的原因是SendMqService 的示例并非从ioc容器得到, 是不是直接new对象了

是的。谢谢老大

0.0又有新的问题,是说插件里的连接工厂有问题

Caused by: org.nutz.ioc.IocException: IocBean[rabbitmq_cf] For object [rabbitmq_cf] - type:[]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 50 more
Caused by: org.nutz.ioc.ObjectLoadException: Object 'rabbitmq_cf' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:166)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
	... 52 more

nutz mvc吗? @IocBy加上*rabbitmq了吗?

@IocBy(type=ComboIocProvider.class, args={"*js","config/", "*anno", "com.hits","*tx","*rabbitmq"})
加了

nutz什么版本?

哦, 那插件版本换成1.r.62吧

老大你再看看什么原因。已经换成1.r.62了

Caused by: java.lang.RuntimeException: IocBean[rabbitmq] fail at field=[factory]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
	... 48 more
Caused by: org.nutz.ioc.IocException: IocBean[rabbitmq_cf -> conf] For object [conf] - type:[]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.ioc.impl.ObjectMakerImpl$1.born(ObjectMakerImpl.java:88)
	at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 50 more
Caused by: org.nutz.ioc.ObjectLoadException: Object 'conf' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:166)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
	... 57 more

你需要定义一个bean,叫conf,类型是PropertiesProxy,可以参考nutzbook,这个conf对象已经成为标配,默认用户已经定义

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