Let me explain singleton in super easy terms:
A singleton means:
"Spring will only create one single instance of this class and reuse it everywhere."
When you mark a class with @Component
, @Service
, or @Bean
(inside @Configuration
):
java
CopyEdit
@Component
public class MyService {
// Spring creates only ONE of this
}
Spring will: