In my application.properties
I add some custom attributes.
custom.mail.property.subject-message=This is a ? ? ü ? problem
In this class I have the representation of the custom attributes.
@Component
@ConfigurationProperties(prefix="custom.mail.property")
public class MailProperties {
private String subjectMessage;
public String getSubjectMessage() {
return subjectMessage;
}
public void setSubjectMessage(String subjectMessage) {
this.subjectMessage = subjectMessage;
}
And here I use my MailProperties
:
@Service
public class SimpleUnknownResponseMessage extends MailProperties implements UnknownResponseMessage{
private JavaMailSender javaMailSender;
@Autowired
public SimpleUnknownResponseMessage(JavaMailSender javaMailSender) {
this.javaMailSender = javaMailSender;
}
@Override
public void placeUnknownResponse(BookResponse bookResponse) {
MimeMessage message = javaMailSender.createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(message, "UTF-8");
helper.setSubject(this.getSubjectMessage());
javaMailSender.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
While debugging I can see that my this.getSubjectMessage()
variable has this value inside: This is a ?¤ ?? ?? ? problem
. So before sending my mail I already have an UTF-8 encoding problem.
I already checked the encoding of the application.properties
file and its UTF-8.
My IDE(STS/Eclipse) and the project properties are also set on UTF-8.
How can I set the UTF-8 encoding for the text of my custom attributes in the application.properties
file?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…