spring-bootannotationsjasyptmail-sender

With Spring-Boot auto-configured JavaMailSender, how to support encrypted (username/password) properties using Jasypt library?


JavaMailSender is being auto configured in my Spring Boot application. How can I use annotations to allow encrypted values in my properties file for the properties "spring.mail.username"and "spring.mail.password" using the Jasypt library? please help.

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SimpleMailController {

@Autowired
private JavaMailSender sender;

Solution

  • I was able to crack it.

    1. Add the annotation @EnableEncryptableProperties to my Application class.
    2. Add jasypt spring boot starter dependency in gradle script -

    compile('com.github.ulisesbocchio:jasypt-spring-boot-starter:2.0.0')

    All the properties used in my application now support encrypted values by default.