April 2018
Intermediate to advanced
246 pages
6h 11m
English
As we have seen, the prototype scope is used to get a new instance of a bean every time when requested. To understand prototype, we will take the same bean class, EmailService, and we just need to change the value of the scope attribute for the emailService bean in application-context.xml:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="emailService" class="com.packt.springbean.EmailService" scope="prototype" /> </beans>
The code used for the singleton scope will the same as before, ...