ZERODAY_GI 2019-08-15 16:46 采纳率: 50%
浏览 4176
已采纳

spring的@Component组件无法注入?

需要注入的类


@Component
public class WXConfig implements com.github.wxpay.sdk.WXPayConfig {



    /**
     * 服务器地址
     */
    @Value("${weChat.domain}")
    private String domain;


    /**
     * 商户Id
     */
    @Value("${weChat.mchId}")
    private String mchId;
    /**
     * 支付key
     */
    @Value("${weChat.key}")
    private String key;

    /**
     * appid
     */
    @Value("${weChat.appId}")
    private String appId;

    /**
     * appSecret
     */
    @Value("${weChat.appSecret}")
    private String appSecret;


    @Override
    public String getAppID() {
        return appId;
    }

    @Override
    public String getMchID() {
        return mchId;
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public InputStream getCertStream() {
        return null;
    }

    /**
     * 连接超时时间
     *
     * @return
     */
    @Override
    public int getHttpConnectTimeoutMs() {
        return 10 * 1000;
    }

    /**
     * 读取超时时间
     *
     * @return
     */
    @Override
    public int getHttpReadTimeoutMs() {
        return 10 * 1000;
    }

    public String getMchId() {
        return mchId;
    }

    public String getAppSecret() {
        return appSecret;
    }

    public String getGrantType() {
        return "authorization_code";
    }

    /**
     * 回调地址
     */
    public String getNotifyURL() {
        return this.domain + "/order/wxPayUnifiedNotify";
    }


}

调用的类


/**
 * 微信相关
 *
 * @author tangchao
 */
@Component
public class WxUtil {


    @Autowired
    private WXConfig wxConfig;

    private final Logger LOG = LoggerFactory.getLogger(this.getClass());


    /**
     * 用户登录
     *
     * @param code          前端登录code
     * @param encryptedData 包括敏感数据在内的完整用户信息的加密数据
     * @param iv            加密算法的初始向量
     * @return 返回用户信息 nickName,avatarUrl,gender,unionid,city,province,country,openid
     * @throws Exception
     */

    public JSONObject loginByWeixin(String code, String encryptedData, String iv) throws Exception {
        WxUtil wxUtil = new WxUtil();

        //根据code去调用接口获取用户openid和session_key
        JSONObject json = wxUtil.getSessionKeyAndOpenid(code);
        System.out.println("返回过来的json数据:" + json.toString());
        //会话秘钥
        String sessionkey = json.get("session_key").toString();
        //用户唯一标识
        String openid = json.get("openid").toString();

        //拿到用户session_key和用户敏感数据进行解密,拿到用户信息。
        String decrypts = wxUtil.decrypt(encryptedData, sessionkey, iv, "utf-8");
        JSONObject jsons = JSONObject.parseObject(decrypts);
        jsons.put("openid", openid);
        return jsons;
    }
}

wxConfig报空指针,为什么?

  • 写回答

2条回答 默认 最新

  • ZERODAY_GI 2019-08-15 17:35
    关注

    谢谢,已经解决了,原来我下面new了一个WXConfig ,使用的WXConfig是手动new出来的,忘记删除了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog