自定义验证消息不起作用.我有一个域类:
...
@RooJpaActiveRecord
public class Letter {
@NotNull(message="{validation.number_empty}")
@Size(min=1,max=20, message="{validation.number_size}")
@Column(length=20, nullable=false)
private String number;
...
}
Run Code Online (Sandbox Code Playgroud)
/WEB-INF/i18n/messages.properties:
#validation
validation.number_size=number must be more than 1 and less than 20 symbols
...
Run Code Online (Sandbox Code Playgroud)
我想在表单提交期间验证该域类的一些字段.验证工作,但我得到输出消息:
{} validation.number_size
而不是预期的字符串:数字必须大于1且少于20个符号 在我的项目的其他位置,我使用属性文件中的消息成功.
/WEB-INF/spring/webmvc-config.xml
<bean
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
id="messageSource"
p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application"
p:fallbackToSystemLocale="false">
</bean>
Run Code Online (Sandbox Code Playgroud)
此外,我试过,但没有成功:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:WEB-INF/i18n/messages</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="ignoreResourceNotFound" value="true"/>
</bean>
Run Code Online (Sandbox Code Playgroud) 为什么下面的代码不是死锁而且运行正常?
public class Concurrent {
public static void main(String[] args) {
Concurrent my = new Concurrent();
my.method1();
}
private synchronized void method1() {
System.out.println("method1");
method2();
}
private synchronized void method2() {
System.out.println("method2");
}
}
Output:
method1
method2
Run Code Online (Sandbox Code Playgroud)
当我调用method1()时,监视器被锁定.JVM或编译器无法调用method2(),因为此方法也由"my"对象的监视器同步.但它运作正常.