Bean Scopes - Overview - Spring Framework Tutorial
Bean Scopes - Overview is a free tutorial by Chad Darby from Spring Framework course
Link to this course(Special Discount):
https://www.udemy.com/course/spring-hibernate-tutorial/?ranMID=39197&ranEAID=Gw%2FETjJoU9M&ranSiteID=Gw_ETjJoU9M-qv.7AKCxyysYdU6Yc_UEdA&utm_source=aff-campaign&LSNPUBID=Gw%2FETjJoU9M&utm_medium=udemyads
This is the best Spring Framework Course
Course summary:
Develop a REAL-TIME project with Spring MVC, Spring REST, Spring Boot and Hibernate CRUD ... all from SCRATCH
You will TYPE IN EVERY LINE of code with me in the videos. I EXPLAIN every line of code to help you learn!
LEARN key Spring 5 features: Core, Annotations, Java Config, AOP, Spring MVC, Hibernate and Maven
I am a RESPONSIVE INSTRUCTOR ... post your questions and I will RESPOND in 24 hours.
POPULAR VIDEOS for: Spring Boot 2, Spring Security, Spring REST, Spring Data JPA, Spring Data REST and Thymeleaf
Join an ACTIVE COMMUNITY of 140,000+ students that are already enrolled! Over 38,000+ Reviews - 5 STARS
Students have LANDED NEW JOBS with the skills from this course. Spring and Hibernate developers are in HIGH-DEMAND!
You can DOWNLOAD all videos, source code and PDFs. Perfect for offline LEARNING and REVIEW.
English
Tutor: In this video, we're gonna discuss the bean scopes available in Spring. So what exactly are scopes? Well, a scope refers to the lifecycle of a bean, for example, it tells you how long the bean will live, how many instances will be created and also how is the bean shared in the Spring environment? So the default scope for a bean is singleton, so here's an example here of just some bean code, that we had earlier and we didn't explicitly give a scope, so by default, the scope is singleton. But now you're probably wondering, well, what exactly is a singleton? (laughs) we know it's a default scope, but what is it? Well, for a singleton, the Spring Container creates only one instance of the bean, it's cached in memory and then all requests for that bean will return a shared reference to the same bean, so the end result is that there is only one bean and everyone will share it. Here's a nice diagram to kind of show you this example. In this example, we have theCoach equals context.getBean myCoach and it'll give you a reference to like a TrackCoach, that you have defined and then later on in the code, if you would also do a similar thing, saying context.getBean myCoach, the same bean id, then it'll basically give you a reference to the same bean. We have these two object references here and they point to the same area of memory or they point to the same bean, so again, Spring makes use of a singleton, it'll create only one bean and then share it for everyone who requests that bean, so the singleton scope is default and the best use case for this is for a stateless bean, where you don't need to maintain any state. You can explicitly specify the bean scope, I mean, by now you know that by default, you have the singleton scope, but if you want to explicitly specify, then you make use of the scope attribute, so you say scope equals singleton and that'll make it a singleton bean and that's kind of the preferred approach to minimize the number of beans, that are created. But now, there are additional Spring bean scopes, that you can make use of. We've already covered singleton, there's also the prototype scope, which creates a new bean instance for each container request and we'll see examples of that coming up and we'll also use that as a demo in the video coming up, then the next three items here, request, session and global-session, these scopes are only used in a web environment, so request is for a given web request, session is for a HTTP web session, for like session tracking for like maybe a shopping cart or something and then global-session is scope application-wide, but we'll talk more about these later, when we get into the Spring MVC section, but for now, we'll simply focus on singleton and prototype. So here's an example of using prototype scope, so again, remember, prototype scope, a new object is created for each request, so in this example here, I have my bean id of myCoach and I have scope equals prototype, so that means that every time I make a request for this myCoach, they'll create a new instance each time. So, a nice little diagram here. So the line of code at the top, theCoach equals context.getBean myCoach, it'll create a new instance of that bean, I'll get a reference to it and then a similar thing here, when I say alphaCoach equals context.getBean myCoach, it'll create a new object for you and you'll have your own reference. So the prototype scope is good for keeping track of stateful data, so again, whenever you see prototype, just think of the new keyword, it's gonna create a new bean for each request for that component or that object. Alright, so this is some really good stuff. Let's go ahead and move forward, in the next videos,
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Bean Scopes - Overview - Spring Framework Tutorial», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.