LEARNER OLY ASKING
LEARNER OLY ASKING

Reputation: 17

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

Upvotes: 0

Views: 369

Answers (1)

Nice Books
Nice Books

Reputation: 1861

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.

Upvotes: 2

Related Questions