java.lang.ClassCastException:com.olm.om.domain.User无法转换为java.util.Map

时间:2020-11-05 09:47:37

标签: java spring spring-boot maven spring-mvc

 @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);
    }

错误来自此代码。.在运行java.lang.ClassCastException之类的给出错误之后,我在New User注册后发送邮件:com.olm.om.domain.User无法转换为java.util.Map < / p>

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

错误源于此代码:-

> for (Map<String,Object> data : allUsersForSendingNotification.get()) 
                  

该代码已根据此代码实现

@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());
     }

0 个答案:

没有答案