in Java HV000030: No validator could be found for constraint ‘javax.validation.constraints.Email’

Tags: , , , ,

I am trying to send html email notification when user submits a form but I am getting an error. Can you please look at it?

There was an unexpected error (type=Internal Server Error, status=500).HV000030: No validator could be found for constraint 'javax.validation.constraints.Email' validating type 'java.lang.String'. Check configuration for 'email'

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint ‘javax.validation.constraints.Email’ validating type ‘java.lang.String’. Check configuration for ’email’


import javax.validation.constraints.Email;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

  public class MailRequest {
  private String name;
  private String to;
  private String from;
  private String subject;
  public MailRequest(String to) { = "Some name"; = to;
      this.from = "";
      this.subject = "Confirmation";

 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 public class MailResponse {
   private String message;
   private boolean status;
   public String getMessage() {
     return message;
   public void setMessage(String message) {
      this.message = message;
   public boolean isStatus() {
      return status;
   public void setStatus(boolean status) {
      this.status = status;


   import org.springframework.context.annotation.Configuration;
  import org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean;
  public class EmailConfig {
    public FreeMarkerConfigurationFactoryBean factoryBean() {
       FreeMarkerConfigurationFactoryBean bean = new FreeMarkerConfigurationFactoryBean();
      return bean;

import java.nio.charset.StandardCharsets;
import java.util.Map;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.validation.UnexpectedTypeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class EmailService {
private JavaMailSender sender;
private Configuration config;

 public MailResponse sendEmail(MailRequest request, Map<String, Object> model) {
    MailResponse response = new MailResponse();
    MimeMessage message = sender.createMimeMessage();
    try {
        // set mediaType
        MimeMessageHelper helper = new MimeMessageHelper(message, MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,

        Template t = config.getTemplate("email-template.ftl");
        String html = FreeMarkerTemplateUtils.processTemplateIntoString(t, model);

        helper.setText(html, true);

        response.setMessage("mail send to : " + request.getTo());

    } catch (UnexpectedTypeException | MessagingException | IOException | TemplateException e) {
        response.setMessage("Mail Sending failure : "+e.getMessage());

    return response;

This is in my main Service and I call this method from Controller.

public MailResponse sendConfirmationEmail(String email) throws UnexpectedTypeException {
    Map<String, Object> modelsMap = new HashMap<>
    modelsMap.put("name", "Tural");
    modelsMap.put("Location", "Baku");
    MailRequest mailRequest = new MailRequest(email);
    return emailservice.sendEmail(mailRequest, modelsMap);

From my Controller I am passing email address to my method:

 @Email @RequestParam("email") String email,

I did some research and upgraded hibernate-validator in pom.xml as well but doesn’t work


Thank you for your help!!


The solution for this problem is to add a message in the annotation @Email.

@Email(message = "Email should be valid") 

Depends on the implementation that you use this attribute is required or not.

Source: stackoverflow