spring-boot - 在 Spring Boot 中更改 serverTimezone
问题描述
我想将 serverTimezone 更改为 GMT+3。我试试这个但不工作
spring.datasource.url=jdbc:mysql://localhost:3306/example?useSSL=false&serverTimezone=GMT+3&useLegacyDatetimeCode=false
Caused by: java.sql.SQLException: No timezone mapping entry for 'GMT 3'
但如果我运行它,它正在使用 GMT-3
spring.datasource.url=jdbc:mysql://localhost:3306/example?useSSL=false&serverTimezone=GMT-3&useLegacyDatetimeCode=false
如何将其更改为 GMT+3 ?
解决方案
请在主启动应用程序中覆盖 PostConstruct,如下所示
@PostConstruct
public void init()
{
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Kolkata"));
}
将 Asia/Kolkata 替换为您的时区
推荐阅读
- php - 从 WordPress 菜单或子菜单项获取 ACF 字段
- ruby-on-rails - 通过 API 获取仅在 shopify 商店菜单中可用的集合
- angular - 如何使用 angular 9 $localize 和复数?
- python - 将 pandas 数据框转换为以行元素为主键、dict 为值的字典
- linux - 为什么 netstat -an 显示了这么多从本地端口到端口 111 的 TIME_WAIT 连接?
- spring - 更新 JPA(Hibernate)实体的更好方法是:事务性或非事务性,为什么?
- c# - 在 iOS 上,当应用程序进入后台时 UnityWebRequest 下载停止
- node.js - Angular 7 CLI 安装问题
- hibernate - 带有@MapsId 的单向@OneToOne 不适用于延迟加载
- probability - 概率和练习