使用配置设置连接超时
问题描述:
我意识到我没有使用setQueryTimeOut
方法为JDBCTemplate
设置超时时间。我的代码在生产中,因为我希望解决方案能够从某些配置中设置超时而不是重新编译代码。有没有办法通过说数据源配置或Java以外的任何其他属性来设置查询超时。使用配置设置连接超时
我通过接受的解决方案尝试了这个post。没有为我工作。我得到org.springframework.beans.NotWritablePropertyException: Invalid property 'connectionProperties' of bean class
答
您可以使用queryTimeout
场配置:
- 在你JDBCTempalte XML -
<property name="queryTimeout" value="${query.timeout}
/> - 使用
PropertyPlaceholderConfigurer
加载从classpath中的.properties
文件属性。最简单的方法就是通过<context:property-placeholder location=".." />
- 添加
query.timeout=x
在.properties
文件