gpt4 book ai didi

java - 使用配置设置连接超时

转载 作者:行者123 更新时间:2023-11-30 09:49:18 25 4
gpt4 key购买 nike

我意识到我没有为 JDBCTemplate 设置超时使用 setQueryTimeOut 方法。我的代码正在生产中,因为我理想情况下想要一个解决方案来设置某些配置的超时而不是重新编译代码。有没有办法通过数据源配置或 Java 之外的任何其他属性来设置查询超时。

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

最佳答案

您可以使用 queryTimeout配置字段:

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

关于java - 使用配置设置连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5861789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com