java - how to Inject Calendar getInstance in Spring , please
问题描述
<bean id="date" class="java.util.Calendar.getInstance" />
how can i inject Calendar instance Please help
i am confused what to use ,i am new to spring In date where new keyword is required is fine but here what have to do
解决方案
In a <bean>
declaration class
should specify the complete classname. getInstance
is a factory method & hence it should be as follows:
<bean id="date" class="java.util.Calendar" factory-method="getInstance"/>
It might be better to use the java.time
classes introduced in Java 8, rather than the old java.util.Calendar
& java.util.Date
.
<bean id="date" class="java.time.LocalDate" factory-method="now">
NB: Nevertheless, I can't think of a valid use case, to have the date as a bean.
推荐阅读
- node.js - 需要使用节点 js 将 JSON 从端点发布到 Prometheus
- shell - 在 HDFS 中查找并删除零字节文件
- datatable - 使用ajax在数据表中进行简单分页而不从服务器发送总数
- mysql - MySQL选择顺序,其中多列是条件
- sql - 如何避免在 Openrowset 中将 Decimal value 读取为 Float
- grails - Grails:java.lang.NullPointerException:无法在空对象上调用方法 clearTime()
- node.js - 显示角度 cli 安装的错误
- html - HTML 导入每个模块而不是链接导入
- php - 从多个表中插入数据到表中
- python - 在 Python3 中解密后无法从加密文件中恢复原始图像文件