java.util.TimeZone 新加方法 getTimeZone(ZoneId zoneId) 導致的問題


最近接受的項目中用spring配置了一個TimeZone對象:

<bean id ="timeZone4Job" class="java.util.TimeZone" factory-method="getTimeZone">
          <constructor-arg value="GMT+8:00"/>
</bean>

以前是運行在 1.7 中,沒什么問題。今天換了1.8的sdk,spring開始報錯,發現原來在1.8里面新加入了方法 getTimeZone(ZoneId zoneId),spring會嘗試轉換GMT+8:00為ZoneId,而坑爹的是ZoneId.of(String zoneId) 支持的格式少,直接報錯。

修改Spring配置如下,問題解決。

<bean id ="timeZone4Job" class="java.util.TimeZone" factory-method="getTimeZone">
          <constructor-arg value="GMT+8:00" type="String"/>
</bean>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM