NutzCN Logo
问答 极光推送JPushClient的ioc注入问题
发布于 2550天前 作者 quinnxiao 1613 次浏览 复制 上一个帖子 下一个帖子
标签:
JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, ClientConfig.getInstance());

这是初始化方法,我写的jpush.js是这样子的

var ioc={
    clientConfig : {
        type : "cn.jiguang.common.ClientConfig",
        singleton : true
    },
    jPushClient : {
        type : "cn.jpush.api.JPushClient",
        singleton : false,
        args : [{java:"$conf.get('jpush.master_secret')"}, {java:"$conf.get('jpush.app_key')"},null,{refer:"clientConfig"}]
    }
};

ClientConfig是单利模式的,但是通过ioc拿到JPushClient报错了,请问这个该怎么弄呢
JPushClient jpushClient = config.getIoc().get(JPushClient.class);


Caused by: java.lang.IllegalArgumentException: array element type mismatch at java.lang.reflect.Array.set(Native Method) at org.nutz.lang.Mirror.evalArgToRealArray(Mirror.java:1287) at org.nutz.lang.Mirror.evalArgToSameTypeRealArray(Mirror.java:1249) at org.nutz.lang.born.Borns.evalWithArgs(Borns.java:76) at org.nutz.lang.born.Borns.eval(Borns.java:58) at org.nutz.lang.Mirror.getBorning(Mirror.java:952) at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:107) ... 57 more
DXJ50: 2017-12-29 10:37:54,274 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(clientConfig) in JsonLoader(paths=[dao.js, ioc/upload.js, ioc/mail.js, ioc/jpush.js])
DXJ50: 2017-12-29 10:37:54,274 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.nutz.ioc.impl.NutIoc - 	 >> Make...'clientConfig'<>
DXJ50: 2017-12-29 10:37:54,274 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.nutz.ioc.aop.impl.DefaultMirrorFactory - Load class cn.jiguang.common.ClientConfig without AOP
DXJ50: 2017-12-29 10:37:54,274 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.nutz.ioc.impl.ScopeContext - Save object 'clientConfig' to [app] 
org.nutz.ioc.IocException: IocBean[jPushClient] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
	at com.hxd.Startup.init(Startup.java:46)

ClientConfig是这样的

public class ClientConfig extends HashMap<String, Object> {
    public static final String DEVICE_HOST_NAME = "device.host.name";
    public static final Object DEVICE_HOST_NAME_SCHEMA = String.class;
    public static final String DEVICES_PATH = "devices.path";
    public static final Object DEVICES_PATH_SCHEMA = String.class;
    public static final String TAGS_PATH = "tags.path";
    public static final Object TAGS_PATH_SCHEMA = String.class;
    public static final String ALIASES_PATH = "aliases.path";
    public static final Object ALIASES_PATH_SCHEMA = String.class;
    public static final String PUSH_HOST_NAME = "push.host.name";
    public static final Object PUSH_HOST_NAME_SCHEMA = String.class;
    public static final String PUSH_PATH = "push.path";
    public static final Object PUSH_PATH_SCHEMA = String.class;
    public static final String PUSH_VALIDATE_PATH = "push.validate.path";
    public static final Object PUSH_VALIDATE_PATH_SCHMEA = String.class;
    public static final String REPORT_HOST_NAME = "report.host.name";
    public static final Object REPORT_HOST_NAME_SCHEMA = String.class;
    public static final String REPORT_RECEIVE_PATH = "report.receive.path";
    public static final Object REPORT_RECEIVE_PATH_SCHEMA = String.class;
    public static final String REPORT_USER_PATH = "report.user.path";
    public static final Object REPORT_USER_PATH_SCHEMA = String.class;
    public static final String REPORT_MESSAGE_PATH = "report.message.path";
    public static final Object REPORT_MESSAGE_PATH_SCHEMA = String.class;
    public static final String REPORT_STATUS_PATH = "report.status.path";
    public static final Object REPORT_STATUS_PATH_SCHEMA = String.class;
    public static final String SCHEDULE_HOST_NAME = "schedule.host.name";
    public static final Object SCHEDULE_HOST_NAME_SCHEMA = String.class;
    public static final String SCHEDULE_PATH = "schedule.path";
    public static final Object SCHEDULE_PATH_SCHEMA = String.class;
    public static final String GROUP_PUSH_PATH = "group.push.path";
    public static final Object GROUP_PUSH_PATH_SCHEMA = String.class;
    public static final String SSL_VERSION = "ssl.version";
    public static final Object SSL_VERSION_SCHEMA = String.class;
    public static final String DEFAULT_SSL_VERSION = "TLS";
    public static final String MAX_RETRY_TIMES = "max.retry.times";
    public static final Object MAX_RETRY_TIMES_SCHEMA = Integer.class;
    public static final int DEFULT_MAX_RETRY_TIMES = 3;
    public static final String READ_TIMEOUT = "read.timeout";
    public static final Object READ_TIMEOUT_SCHEMA = Integer.class;
    public static final int DEFAULT_READ_TIMEOUT = 30000;
    public static final String CONNECTION_REQUEST_TIMEOUT = "connection.request.timeout";
    public static final Object CONNECTION_REQUEST_TIMEOUT_SCHEMA = Integer.class;
    public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT = 10000;
    public static final String CONNECTION_TIMEOUT = "connection.timeout";
    public static final Object CONNECTION_TIMEOUT_SCHEMA = Integer.class;
    public static final int DEFAULT_CONNECTION_TIMEOUT = 5000;
    public static final String SOCKET_TIMEOUT = "socket.timeout";
    public static final Object SOCKET_TIMEOUT_SCHEMA = Integer.class;
    public static final int DEFAULT_SOCKET_TIMEOUT = 10000;
    public static final String APNS_PRODUCTION = "apns.production";
    public static final Object APNS_PRODUCTION_SCHEMA = Integer.class;
    public static final int DEFAULT_APNS_PRODUCTION = -1;
    public static final String TIME_TO_LIVE = "time.to.live";
    public static final Object TIME_TO_LIVE_SCHEMA = Long.class;
    public static final long DEFAULT_TIME_TO_LIVE = -1L;
    private static ClientConfig instance = new ClientConfig();
6 回复
@IocBean
public class MyJpushBean {

    @IocBean(name="jpush")
    public JPushClient createJPushClient() {
        return new JPushClient(MASTER_SECRET, APP_KEY, null, ClientConfig.getInstance());
    }
}

@wendal 我想通过ioc.js文件注入要怎么弄呢

试试这样

var ioc={
    clientConfig : {
        type : "cn.jiguang.common.ClientConfig",
        factory : "cn.jiguang.common.ClientConfig#getInstance"
    },
    jPushClient : {
        type : "cn.jpush.api.JPushClient",
        singleton : false,
        args : [{java:"$conf.get('jpush.master_secret')"}, {java:"$conf.get('jpush.app_key')"},null,{refer:"clientConfig"}]
    }
};

你的ClientConfig 类为啥跟jpush带的ClientConfig一样名字呢? 而且不是它的子类

@wendal 试了下还是不行

org.nutz.ioc.IocException: IocBean[jPushClient] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
	at com.hxd.dao.SimplTest.test16(SimplTest.java:214)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.IllegalArgumentException: array element type mismatch
	at java.lang.reflect.Array.set(Native Method)
	at org.nutz.lang.Mirror.evalArgToRealArray(Mirror.java:1287)
	at org.nutz.lang.Mirror.evalArgToSameTypeRealArray(Mirror.java:1249)
	at org.nutz.lang.born.Borns.evalWithArgs(Borns.java:76)
	at org.nutz.lang.born.Borns.eval(Borns.java:58)
	at org.nutz.lang.Mirror.getBorning(Mirror.java:952)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:107)
	... 28 more

@wendal 算了还是那个报array错误,我用的这种方式

@IocBean
public class Jpush {

    private static final Logger log = LoggerFactory.getLogger(Jpush.class);

    @Inject("java:$conf.get('jpush.master_secret')")
    private String MASTER_SECRET = null;
    @Inject("java:$conf.get('jpush.app_key')")
    private String APP_KEY = null;

    public void push(){
        JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, ClientConfig.getInstance());
添加回复
请先登陆
回到顶部