java - Springs CustomDateEditor luring to make mistakes? -
let me start couple of facts:
simpledateformat not thread safe proven here: andy grove's blog: simpledateformat , thread safety
when want convert strings parameters of request other objects (like java.util.date) can use java beans' property editor support.
for java.util.date spring offers class conversion you: customdateeditor.
the constructor of class required dateformat first argument. if registration of custom property editors happens each request: injecting simpledateformat (the standard implementation of dateformat) suggested here (please scroll down or use browser's search simpled...), run trap.
what thread safe solution?
configure simpleformatdate scope="request", new instance of simpledateformat instantiated each request.
<bean id="simpledateformat" class="java.text.simpledateformat" scope="request"> <constructor-arg value="dd-mm-yyyy"/> </bean> note: may need configure proxy
<beans xmlns:aop="http://www.springframework.org/schema/aop" ... xsi:schemalocation="... http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <bean id="simpledateformat" class="java.text.simpledateformat" scope="request"> <constructor-arg value="dd-mm-yyyy"/> <aop:scoped-proxy /> </bean> ...
Comments
Post a Comment