我使用 spring MessageSource 从我的本地化属性文件中获取消息。
在这种情况下,我在将邮件发送给用户之前使用它来创建邮件:
String eventTitle = tournament.getEvent().getTitle();
String tournamentMessageTitle = messageSource.getMessage("tournament.subscribe_title", new Object[] {eventTitle}, "", locale);
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
String formatedDate = df.format(tournament.getDate());
String barName = bar.getName();
String tournamentMessageContent = messageSource.getMessage("tournament.subscribe_content", new Object[] {username, eventTitle, formatedDate, barName}, "", locale);
这是 message.properties 中的属性
tournament.subscribe_title = You signed up for "{0}"
tournament.subscribe_content = Hello {0], <br /><br /> You’ve sucessfully signed up for “{1}”. See you on {2} at Meltdown {3}!<br/><br/>You’ll have to confirm your participation with an admin prior to the start of the event.<br/><br/>See you soon!<br/><br/>The Meltdown {3} team
所以在这里,我们有两种messageSource.getMessage的用法。第一个有效,第二个抛出 IllegalArgumentException:模式中的不匹配大括号。
我试图更改消息,更改/删除变量,删除引号和双引号,将属性移动到 message.properties 文件中的其他位置,但我总是得到同样的错误