Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,350 --> 00:00:03,060
Instructor: Well, everything's working just fine,
2
00:00:03,060 --> 00:00:05,939
but hey, let's go ahead and break it on purpose.
3
00:00:05,939 --> 00:00:09,480
I wanna see how Spring can handle things if I change up
4
00:00:09,480 --> 00:00:11,930
some of the packages or move things around a bit.
5
00:00:15,450 --> 00:00:18,540
Let's go ahead and select the Java folder in the list here
6
00:00:18,540 --> 00:00:20,613
and we're gonna create a new package.
7
00:00:30,720 --> 00:00:32,009
And the name of the new package,
8
00:00:32,009 --> 00:00:34,683
I'll call it, com.luv2code.util.
9
00:00:41,850 --> 00:00:43,230
And so, the important thing to notice
10
00:00:43,230 --> 00:00:46,770
is that it's not a sub-package of our Spring core demo.
11
00:00:46,770 --> 00:00:47,760
It's outside of that.
12
00:00:47,760 --> 00:00:49,620
So, we may have some issues
13
00:00:49,620 --> 00:00:51,820
with some of our default component scanning.
14
00:00:56,850 --> 00:01:00,300
And what I'll do here is I'll move into the Spring core demo
15
00:01:00,300 --> 00:01:05,300
common package and I will move coach and cricket coach
16
00:01:05,489 --> 00:01:08,463
to this new util package that I just created.
17
00:01:17,107 --> 00:01:19,357
(no sound)
18
00:01:22,450 --> 00:01:24,783
Okay, so that looks okay so far.
19
00:01:28,500 --> 00:01:31,290
Now, notice our main Spring Boot application
20
00:01:31,290 --> 00:01:33,060
is under Spring core demo.
21
00:01:33,060 --> 00:01:35,580
So, Spring will scan everything in this package
22
00:01:35,580 --> 00:01:37,982
and any sub-packages, but by default
23
00:01:37,982 --> 00:01:42,210
Spring will not component scan this new package here
24
00:01:42,210 --> 00:01:45,213
that I created, com.luv2code.util.
25
00:01:48,213 --> 00:01:51,370
So, let's go ahead and test this out and see what happens.
26
00:01:55,410 --> 00:01:58,680
Ah, application failed to start.
27
00:01:58,680 --> 00:01:59,513
Okay.
28
00:02:02,610 --> 00:02:06,570
A parameter of constructor demo controller required
29
00:02:06,570 --> 00:02:10,320
of being of love to code util coach,
30
00:02:10,320 --> 00:02:13,383
but could not be found, hmm.
31
00:02:20,040 --> 00:02:22,020
Because it, just it's not part
32
00:02:22,020 --> 00:02:24,090
of the default component scanning.
33
00:02:24,090 --> 00:02:25,500
It's just that just won't work.
34
00:02:25,500 --> 00:02:27,480
And so you're like, gosh, what's going on here?
35
00:02:27,480 --> 00:02:30,516
Well now, we need to explicitly tell Spring Boot
36
00:02:30,516 --> 00:02:33,513
how to find these other packages out there.
37
00:02:43,620 --> 00:02:45,420
And so, we can accomplish that by editing
38
00:02:45,420 --> 00:02:47,430
our Spring cord demo application
39
00:02:47,430 --> 00:02:50,973
and updating the annotation Spring Boot application.
40
00:02:52,620 --> 00:02:54,270
Inside of here, I'll explicitly list
41
00:02:54,270 --> 00:02:55,773
the base packages to scan.
42
00:02:58,980 --> 00:03:01,200
So, I give scan base packages
43
00:03:01,200 --> 00:03:03,930
and then I simply set up a common delimited list
44
00:03:03,930 --> 00:03:06,300
of the packages that I want it to scan.
45
00:03:06,300 --> 00:03:09,483
So, I give com.luv2code Spring core demo,
46
00:03:19,650 --> 00:03:23,313
and then, I also give com.luv2code.util.
47
00:03:27,870 --> 00:03:30,660
So, remember, by default of the only component scan
48
00:03:30,660 --> 00:03:33,270
Spring core demo, but we have this util,
49
00:03:33,270 --> 00:03:35,343
so we have to list both of those here.
50
00:03:39,900 --> 00:03:42,183
Let's go ahead and run this and test it out,
51
00:03:43,620 --> 00:03:45,900
and yay, the issue's resolved.
52
00:03:45,900 --> 00:03:48,270
So, the application actually starts up successfully.
53
00:03:48,270 --> 00:03:50,520
We don't have the problem that we had before.
54
00:03:53,220 --> 00:03:54,690
And then, we can test this in our browser
55
00:03:54,690 --> 00:03:56,850
by hitting this endpoint and just doing a reload on it
56
00:03:56,850 --> 00:03:58,800
and we get the data back as desired,
57
00:03:58,800 --> 00:04:00,690
so it's able to find everything.
58
00:04:00,690 --> 00:04:03,000
It's able to perform the injection
59
00:04:03,000 --> 00:04:06,030
and we're all set up because we were very explicit here
60
00:04:06,030 --> 00:04:08,043
by listing out those packages.
61
00:04:12,960 --> 00:04:14,520
All right, now I'm gonna go ahead and move things back
62
00:04:14,520 --> 00:04:17,070
to their original packages, just so we can take advantage
63
00:04:17,070 --> 00:04:19,110
of the default component scanning with Spring Boots.
64
00:04:19,110 --> 00:04:21,420
So, I'll just grab coach and cricket coach.
65
00:04:21,420 --> 00:04:24,633
I'll move those back over to the common package.
66
00:04:33,120 --> 00:04:36,120
And then, this code that I had here, I could delete it,
67
00:04:36,120 --> 00:04:38,010
or in this case I'll just comment it out,
68
00:04:38,010 --> 00:04:39,240
kind of leave it around for a little bit
69
00:04:39,240 --> 00:04:41,240
in case you wanted to refer to it later.
70
00:04:45,240 --> 00:04:47,797
And then, I'll just use a regular Spring Boot application
71
00:04:47,797 --> 00:04:50,970
by itself and make use of the default configuration
72
00:04:50,970 --> 00:04:52,593
the default component scanning,
73
00:04:54,030 --> 00:04:56,190
and I'll save all that stuff and test it
74
00:04:56,190 --> 00:04:57,750
and make sure it still works and great.
75
00:04:57,750 --> 00:05:00,480
So, our app starts up just fine
76
00:05:00,480 --> 00:05:02,670
and swing over to our browser, do a reload here,
77
00:05:02,670 --> 00:05:03,900
and the import works out just fine.
78
00:05:03,900 --> 00:05:05,820
So, we kind of put things back the way
79
00:05:05,820 --> 00:05:08,280
they were set up originally.
80
00:05:08,280 --> 00:05:09,630
Alrighty, so this looks really good.
81
00:05:09,630 --> 00:05:10,470
I'm happy with this.
82
00:05:10,470 --> 00:05:12,524
I hope you had a good chance here of learning about
83
00:05:12,524 --> 00:05:14,790
component scanning with Spring Boot,
84
00:05:14,790 --> 00:05:15,930
the default component scanning,
85
00:05:15,930 --> 00:05:18,930
and also being explicit with custom packages.
86
00:05:18,930 --> 00:05:21,783
Alrighty, good job, my friend.
6815
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.