2011-05-02 139 views
2

我意识到我没有使用setQueryTimeOut方法为JDBCTemplate设置超时时间。我的代码在生产中,因为我希望解决方案能够从某些配置中设置超时而不是重新编译代码。有没有办法通过说数据源配置或Java以外的任何其他属性来设置查询超时。使用配置设置连接超时

我通过接受的解决方案尝试了这个post。没有为我工作。我得到org.springframework.beans.NotWritablePropertyException: Invalid property 'connectionProperties' of bean class

回答

2

您可以使用queryTimeout场配置:

  1. 在你JDBCTempalte XML - <property name="queryTimeout" value="${query.timeout} />
  2. 使用PropertyPlaceholderConfigurer加载从classpath中的.properties文件属性。最简单的方法就是通过<context:property-placeholder location=".." />
  3. 添加query.timeout=x.properties文件