Java EE notebook
  • Introduction
  • /web-customer-tracker
  • Web Service
  • AOP
  • Web Server2(Spring REST)
  • Security
  • Json
  • Web Server VS Application Server VS Web Containers
  • different between Servlet & JSP2
  • DI
  • 0
  • 1annotation inversion of control, bean scope
  • 2 annotation dependency injection
  • 3 annotation bean scope, java code config
  • 4 Spring MVC
  • rest web services
  • Spring-Hibernate0
  • Spring-Hibernate1
  • @ManyToMany
  • spring mvc work flow
  • Spring Security
  • JWT
  • @Autowired
  • Jersey REST Service
  • Spring Bean
Powered by GitBook
On this page

Was this helpful?

Spring Bean

PreviousJersey REST Service

Last updated 6 years ago

Was this helpful?

1. Spring Bean Scopes and Life Cycle - XML

Scopes

defines the scope of the bean object (singleton, prototype, etc). Spring supports five scopes, three of them are available only with the web apps.The default scope is “singleton”, while the “prototype” scope will create a new object every time we instantiate an object.

<bean id = "app" class = "App" scope="prototype"></bean>

. So, lazy instantiation is only useful when the scope is singleton.

Lifecycle of the bean is as the following:

Bean Instantiated -> Dependencies Injected -> Internal Processing -> Custom Init and destroy method(hooks) -> Bean is ready for use.

https://medium.com/omarelgabrys-blog/spring-a-head-start-beans-configuration-part-2-4a8c239b070a
With prototype scope, beans already are lazy instantiated