Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
-: This video will cover Component Scanning with Spring.
Spring will scan your Java classes
or special annotations such as @Component,
and it'll automatically register the beans
in the Spring container.
Let's look at some Java source code here.
So in our project, we currently have
this Spring core demo application.
That's our main Spring Boot application class
that was created by the Spring Initializer.
We also have our RestController that we created
in an earlier video, called DemoController.
Now, in that Spring core demo application,
the one that was created by the Spring Initializer,
note here that it does an import on Spring Boot Application.
So this enables auto configuration, component scanning
and additional configuration with Spring Boot.
And really behind the scenes, this annotation is composed
of the following annotations, enable auto
configuration, component scan and configuration.
So, a bit more here in these annotations.
The @SpringBootApplication is composed
of the following annotations.
@EnableAutoConfiguration enables Spring Boot's
auto configuration support,
@ComponentScan enables component scanning
of the current package and also
recursively scans the sub-packages,
and the @Configuration annotation is able to
register extra beans with the @Bean annotation
or import other configuration classes.
I'll show you some examples
of the configuration annotation a bit later in the course.
And now back to our Java Source Code.
So we know the information here
about the Spring Boot application.
Next we have this Spring application.
And so this allows us to bootstrap our Spring
Boot application, and then we give a reference here
to the actual name of our class,
in this case, SpringcoredemoApplication.
So behind the scenes this will create the application
context, register all the beans, and also start
the embedded server such as Tomcat, et cetera, by default.
Now, a bit more here on component scanning.
By default, Spring Boot starts component scanning
from the same package as your main Spring Boot application.
And also it scans the sub-packages recursively.
This implicitly defines a base search package
that you can make use of.
So it allows you to leverage default component scanning
without having to explicitly referencing
the base package name.
So here's a diagram to kind of pull this together.
We have our Main Spring Boot application class.
It automatically component scans
the package and sub-packages.
We can create any other sub-packages that we want.
We can give these sub-packages any name,
and then it scans everything in core luv2code.springcoredemo
package, and any sub-packages.
So basically it starts scanning
at the Main Spring Boot application class level
and then all sub-packages underneath that.
Now, a common pitfall when you're making use
of Spring Boot, you may say,
Hey, I'm going to use different packages
and move things around and change things up or whatever.
Here's an example.
So we have our Spring Core Demo, that's the package
of our Main Spring Boot application class.
Then, you may create other packages outside of that.
So using this example here of demo utils,
notice here that it's outside of our Spring Core Demo.
And so by default,
Spring Boot will not component scan these packages.
It will only scan the package
of the Main Spring Boot application class and sub-packages.
So this is very important.
So, the default scanning works fine
if everything is under com.luv2code.springcoredemo.
But what about my other packages?
Like I want to use some different names or whatever
like com.luv2code.util, or org.acme.cart,
or edu.cmu.spirit racing systems.
How will this kind of work out,
or how can I configure this accordingly?
Well, what you can do is,
in your Spring Boot application annotation
then you can tell it to scan base packages.
So, here I'm going to explicitly list
the base packages to scan.
And you simply give a comma'd limited list
of those packages that you want Spring Boot to scan.
So, give our com.luv2code.sprincoredemo,
and then luv2code.util, org.acme.cart, edu.cmu.srs.
All right, so this is all really good stuff.
We're going to move into the next video,
we're going to write the code.
I'll show you how to make use
of default scanning, and also I'll show you how
to manually list the actual package scanning.
I'll see ya in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.