Spring Boot Bootcamp – Workbooks and Challenges
)}

Challenge

The goal of this challenge is to loosely couple your code.

Open the challenge

Screen Shot 2022-08-16 at 1.38.03 AM.png

Task 1

As you loosely couple your code, configure the beans using one of these options:

  1. @Service and @Repository annotations.
  2. @Bean Definitions.
  3. XML Configuration.

Task 2

For this challenge, do not directly wire the beans into each field. Have a look at the @Autowired annotation's targets:

@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)

Notice that @Autowired can also be applied to constructors. Your task is to add one constructor inside Controller, and another inside Service. Then, inject the beans into the constructor using @Autowired.

Task 3: Remove @Autowired

You can remove the @Autowired annotation. Spring Boot will automatically inject a dependency into the constructor when it runs. Try it out!

Screen Shot 2022-06-22 at 3.21.48 AM.png

Good Luck!

Feedback Summary
5.0
3 students
5

100%
4

0%
3

0%
2

0%
1

0%
Written Reviews
There are no written reviews yet.