Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring singleton bean construction

I'm new on spring and I want a spring singleton bean to be created when the web application starts, not when it is referenced. Is there a way to achive this? Thanks in advance

like image 632
AgostinoX Avatar asked Dec 22 '25 23:12

AgostinoX


2 Answers

This is the default behaviour. Spring beans are non-lazy singletons by default.

like image 171
Bozho Avatar answered Dec 24 '25 22:12

Bozho


<bean id="Example" class="com.domain.Example" singleton="true" lazy-init="false" />

or

<bean id="Example" class="com.domain.Example" />

lazy-init and singleton are set to this value by default.

like image 40
kalyan Avatar answered Dec 24 '25 20:12

kalyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!