‘WxMpTemplateMessage‘. Cannot be accessed from outside package

news/2024/10/18 12:28:16/

在使用微信第三方SDK实现消息订阅时发现该错误
在这里插入图片描述
在这里插入图片描述
意思是无法在包外调用该方法.在使用依赖包时如果是2.7.0则不会出现该问题.但使用2.9.0以上的版本时则会出现该问题.

<dependency><groupId>com.github.binarywang</groupId><artifactId>weixin-java-mp</artifactId><version>2.7.0</version>
</dependency>

这是因为新版本采用了 lombok的@Builder 注解然后.官网应该是更推荐使用以builder的方法来构造对象,因此直接限制了该类构造器权限,无法在包外访问.
这里可以了解一下 lombok@Builder注解的使用
使用@Builder的优点是:

  • 不需些太多的set方法来定义属性内容
  • 写法更优雅

直接上代码

@Service
@Transactional
public class WeChatService {@Autowiredprivate WxMpService wxMpService;@Autowiredprivate WechatConfig wechatConfig;/*** 预约状态变更消息*/public void applyStatus(){WxMpTemplateMessage.MiniProgram miniProgram = new WxMpTemplateMessage.MiniProgram(wechatConfig.getAppId(), "/pages/home/index");List<WxMpTemplateData> data = Arrays.asList(new WxMpTemplateData("time16.DATA", "预约时间"),new WxMpTemplateData("thing34.DATA", "咨询地点"),new WxMpTemplateData("phone_number4.DATA", "18868812345"),new WxMpTemplateData("thing10.DATA", "备注"));WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder().toUser("openid").templateId(wechatConfig.getTemplateId().get("applyStatus")).miniProgram(miniProgram).data(data).build();try {String s = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);} catch (WxErrorException e) {e.printStackTrace();}}
}

http://www.ppmy.cn/news/590581.html

相关文章

Linux wait()/waitpid()

这里写目录标题 wait()waitpid() wait() 使用wait()函数与waitpid()函数让父进程回收子进程的系统资源&#xff0c;两个函数的功能大致类似&#xff0c;waitpid()函数的功能要比wait()函数的功能更多。 所需头文件&#xff1a; #include<sys/types.h> #include<sys/…

Meteor.call Wrapper

问题&#xff1a;在Meteor开发时&#xff0c;添加一个Loading的功能&#xff08;即使运行Meteor.call显示和隐藏loading overlay&#xff09;在Meteor.call的生命周期上。 不多解释&#xff0c;直接上代码。本人刚入门不久&#xff0c;可能这个方案比较土&#xff0c;不过在有…

Please, don't hate me

Please, dont hate me Please, dont hate me Please, dont hate me Please, dont hate me Please, dont hate me Please, dont hate me Please, dont hate me

warning: push.default is unset错误提示

1 错误还原&#xff1a; 在执行 git push 时看到如下消息: warning: push.default is unset; its implicit value is changing in Git 2.0 from matching to simple. To squelch this message and maintain the current behavior after the default changes, use: git c…

wait()/notify()的使用

wait()/notify() 通常&#xff0c;多线程之间需要协调工作。例如&#xff0c;浏览器的一个显示图片的线程displayThread想要执行显示图片的任务&#xff0c;必须等待下载线程downloadThread将该图片下载完毕。如果图片还没有下载完&#xff0c;displayThread可以暂停&#xff0…

【wait和notify】

文章目录 前言一、wait() 方法1.wait 做的事情:2.代码实现3.wait结束等待的条件 二、notify() 方法1.notify 方法是唤醒等待的线程2.代码演示 三、notifyAll() 方法1代码演示&#xff1a;2.理解 notify 和 notifyAl 四、wait与sleep区别 前言 由于线程之间是抢占式执行的, 因此…

英雄连2一直显示连接relic服务器,英雄连2联机时出现PleaseWait问题的解决方法_英雄连2PleaseWait问题的解决方法_牛游戏网...

联机时出现PleaseWait问题的解决方法&#xff1a; 1. 将Steam和COH2完全关闭 2. 找到Steam文件夹&#xff0c; 找到steam.exe执行文件&#xff0c;在其属性中&#xff0c;选择”兼容性“&#xff0c;取消掉所有打钩的项目&#xff0c;然后单击”更改所有用户的设置“&#xff0…

wait 和 notify

由于线程之间是抢占式执行的&#xff0c;因此线程之间执行的先后顺序难以预知. 但是实际开发中有时候我们希望合理的协调多个线程之间的执行先后顺序 wait( )方法 wait 方法做的事 使当前执行代码的线程进行等待&#xff0c;(把线程放到等待队列中)释放当前的锁满足一定条件…