java.lang.ClassCastException:com.olm.om.domain.User不能强制转换为java.util.Map @Async @凌驾 所有用户的公共无效SendPushNotifiAction(用户用户,可选allUsersForSendingNotification){ StringBuilder收件人=新StringBuilder(“”); if(allUsersForSendingNotification.isPresent()){ 对于(映射数据:allUsersForSendingNotification.get()){ logger.info(“发送电子邮件至”+data.get(“电子邮件”)); recipients.append(data.get(“email”)).append(“,”); MailModel MailModel=new MailModel(“通知:新用户已注册在线制造,请检查并创建请求。”,“new_User_Notification.html”); mailModel.addData(“用户”,用户); mailModel.addTo(data.get(“email”).toString()); this.emailService.sendmail(mailModel); } } MailModel MailModel=new MailModel(“通知:在线制造中提出了新请求,并已向目标用户发送通知。”,“new_request_olm.html”); mailModel.addTo(“support@onlinemanufacturing.in"); mailModel.addData(“用户”,用户); addData(“targetedUsers”,recipients.toString()); this.emailService.sendmail(mailModel); }

java.lang.ClassCastException:com.olm.om.domain.User不能强制转换为java.util.Map @Async @凌驾 所有用户的公共无效SendPushNotifiAction(用户用户,可选allUsersForSendingNotification){ StringBuilder收件人=新StringBuilder(“”); if(allUsersForSendingNotification.isPresent()){ 对于(映射数据:allUsersForSendingNotification.get()){ logger.info(“发送电子邮件至”+data.get(“电子邮件”)); recipients.append(data.get(“email”)).append(“,”); MailModel MailModel=new MailModel(“通知:新用户已注册在线制造,请检查并创建请求。”,“new_User_Notification.html”); mailModel.addData(“用户”,用户); mailModel.addTo(data.get(“email”).toString()); this.emailService.sendmail(mailModel); } } MailModel MailModel=new MailModel(“通知:在线制造中提出了新请求,并已向目标用户发送通知。”,“new_request_olm.html”); mailModel.addTo(“support@onlinemanufacturing.in"); mailModel.addData(“用户”,用户); addData(“targetedUsers”,recipients.toString()); this.emailService.sendmail(mailModel); },java,spring,spring-boot,maven,spring-mvc,Java,Spring,Spring Boot,Maven,Spring Mvc,错误来自此代码。。我在新用户注册后发送了一封邮件,在运行它的给定错误后,如java.lang.ClassCastException:com.olm.om.domain.User无法转换为java.util.Map 位于com.olm.om.notification.service.EmailNotificationService.SendPushNotificationForAllUsers(EmailNotificationService) 错误来自以下代码:- @Async @Ov

错误来自此代码。。我在新用户注册后发送了一封邮件,在运行它的给定错误后,如java.lang.ClassCastException:com.olm.om.domain.User无法转换为java.util.Map

位于com.olm.om.notification.service.EmailNotificationService.SendPushNotificationForAllUsers(EmailNotificationService)

错误来自以下代码:-

 @Async
    @Override
    public void sendPushNotifactionForAllUsers(User user, Optional<List<Map<String, Object>>> allUsersForSendingNotification) {
        StringBuilder recipients = new StringBuilder("");
        if(allUsersForSendingNotification.isPresent()) {
            for (Map<String,Object> data : allUsersForSendingNotification.get()) { 
                logger.info("Sending email to " + data.get("email"));
                recipients.append(data.get("email")).append(", ");
                  MailModel mailModel = new MailModel("Notification : New User has been Register On Online Manufacturing Please Check and Create Request.", "new_User_notification.html");
                  mailModel.addData("user", user);
                  mailModel.addTo(data.get("email").toString());
                  this.emailService.sendEmail(mailModel);
              }
        }
            MailModel mailModel = new MailModel("Notification : New request has been raised in Online Manufacturing and notification has been sent to targetted users.", "new_request_olm.html");
            mailModel.addTo("support@onlinemanufacturing.in");
            mailModel.addData("user" , user);
            mailModel.addData("targettedUsers", recipients.toString());
            this.emailService.sendEmail(mailModel);
    }
(映射数据:allUsersForSendingNotification.get())的 该代码已从该代码实现

> for (Map<String,Object> data : allUsersForSendingNotification.get()) 
                  
@Async
公共无效sendPushNotifications(用户){
可选的allUsersForSendingNotification=this.getAllUsersForSendingNotification();
此.emailNotificationService.SendPushNotifiActionforAllUsers(用户,allUsersForSendingNotification);}
公共可选getAllUsersForSendingNotification(){
返回可选的.of(this.userDao.getUserByUserName2());
}

请在您创建\填充此
可选allUsersForSendingNotification的位置共享一段代码
@Async
    public void sendPushNotifications(User user) {
        Optional<List<Map<String, Object>>> allUsersForSendingNotification = this.getAllUsersForSendingNotification();
        this.emailNotificationService.sendPushNotifactionForAllUsers(user, allUsersForSendingNotification);}

 public Optional<List<Map<String, Object>>> getAllUsersForSendingNotification() {
            return Optional.of(this.userDao.getUserByUserName2());
     }