NutzCN Logo
问答 nutz微信 protected WxJsapiTicketStore jsapiTicketStore; 为null
发布于 2726天前 作者 蛋蛋的忧伤 1703 次浏览 复制 上一个帖子 下一个帖子
标签:

我使用nutz对微信开发提供包,然后按规定写了配置文件,也成功注入 private WxApi2 wxApi; 然后我调用wxApi.getJsapiTicket(); 发生了空指针:

[DEBUG] 10:17:13.009 com.infogather.mvc.LogTimeProcessor.process(LogTimeProcessor.java:30) - [ GET]URI=/infogather/weixin/getTicket 261647ms
java.lang.NullPointerException
	at org.nutz.weixin.impl.AbstractWxApi2.getJsapiTicket(AbstractWxApi2.java:307)
	at com.infogather.controll.WeixinModule.getTicket(WeixinModule.java:87)
	at com.infogather.controll.WeixinModule$$FASTCLASS._invoke(WeixinModule.java:1)
	at org.nutz.lang.reflect.AbstractFastClass.invoke(AbstractFastClass.java:143)
	at org.nutz.lang.reflect.FastClassFactory.invoke(FastClassFactory.java:67)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.infogather.mvc.LogTimeProcessor.process(LogTimeProcessor.java:23)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at com.infogather.filters.CheckSessionForservlet.doFilter(CheckSessionForservlet.java:41)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)

我跟入getJsapiTicket方法,发现这句抛出异常,

WxJsapiTicket at = jsapiTicketStore.get();

断点查看后 发现 protected WxJsapiTicketStore jsapiTicketStore; 为null,难道是需要我手动给他搞出来?

15 回复

嗯,设置一下吧

恩, 应该添加个默认值

好了,提交了

我是应该去下载新的包么

mvn的话, force update一下完事

我的maven坐标为:

<dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzwx</artifactId>
            <version>1.r.61.r2</version>
        </dependency>

开始是1.r.60来着,然后换了下最新的,然后我看到相关代码有所改动

  public String getJsapiTicket() {
        WxJsapiTicket at = this.jsapiTicketStore.get();
        if(at == null || (long)at.getExpires() < (System.currentTimeMillis() - at.getLastCacheTimeMillis()) / 1000L) {
            Object var2 = this.lock;
            synchronized(this.lock) {
                WxJsapiTicket at_forupdate = this.jsapiTicketStore.get();
                if(at_forupdate == null || (long)at_forupdate.getExpires() < (System.currentTimeMillis() - at_forupdate.getLastCacheTimeMillis()) / 1000L) {
                    this.reflushJsapiTicket();
                }
            }
        }

        return this.jsapiTicketStore.get().getTicket();
    }

但jsapiTicketStore还是为null......依然是空指针

1.r.62-SNAPSHOT

找不到这个版本的包啊....

setting.xml配置

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
            http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository>E:\Dev\apache-maven-3.5.0\repository</localRepository>
    <interactiveMode>true</interactiveMode>
    <usePluginRegistry>false</usePluginRegistry>
    <offline>false</offline>
    <mirrors>
    <mirror>
		<id>nexus-aliyun</id>
		<mirrorOf>central</mirrorOf>
		<name>Nexus aliyun</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public</url>
	</mirror>	
  </mirrors>
</settings>

maven坐标:

  <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzwx</artifactId>
            <version>1.r.62-SNAPSHOT</version>     //报错
        </dependency>

找不到包呢....

挖槽......我加上这些配置就ok了

<repositories>
        <repository>
            <id>nutz</id>
            <url>https://jfrog.nutz.cn/artifactory/jcenter</url>
        </repository>
        <repository>
            <id>nutz-snapshots</id>
            <url>https://jfrog.nutz.cn/artifactory/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>

真是什么技术不懂原理不全面了解都会出问题...

感谢wendal,让程序员更加美好.(〜^㉨^)〜

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