Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave
Spring Boot Assignment: Dependency Injection with Repositories

Step 1: Create a new Spring Boot project

Assignment 1 Summary Build a new Spring project which highlights Dependency Injection of a repository. This has to be created using JDK 11 and It has to be done using Java Enterprise Eclipse. This is Spring Boot assignment. I will be attaching the sample programs and please follow those steps and techniques only. This Assignment is very similar to sample attached along with this file and named as Week2Class2SpringBootWithDI. Step 1 Create a new Spring Boot project named ex22_injectionAndRepositories using Spring Web and Thymeleaf repos. In your project, create a new class in a ca.whatevercollege..controllers package called CourseController. Annotate your CourseController class with Controller. Create a public method called index which returns a String and which takes a Model model as a parameter. Annotate your method to handle incoming GET requests made to “/”. Create a new HTML 5 file named index.html inside your src/main/resources / templates directory. Create a new HTML form in index.html which POSTS to “processForm” with the following fields:  A number field named id A text field named prefix A number field named code  A text field named name A submit button Back at the CourseController, create a method to handle POSTs to “processForm”. Your method should also retrieve the id, prefix, code, and name Request Parameters. Step 2 Create a second class called Course inside a src/main/java / ca.whatevercollege..beans package. Inside Course, create private properties to store the following:  A private Long id A private String prefix  A private int code A private String name Right-click on the code in the Course class ? Source ? Generate Getters and Setters, and generate all getters and setters as well as the toString method. Wow! Super useful! Similarly, right-click on the code in the Course class ? Source ? Generate Constructor using Fields, and generate an All Arguments constructor. That is, a constructor which initializes all arguments. Repeat for a No-Args constructor. This means create a constructor with no arguments (aka a default constructor) by ensuring no property checkboxes are selected. Generate a ToString method, as well as an Equals and Hashcode for all the fields as well. They come in handy! Press ctrl-shift-f to auto-format your code! Amazing!!! Step 3 Create a new Interface in a ca.whatevercollege..repositories package called CourseList. Inside your interface, type the following method signatures: public List getCourseList(); public void setCourseList(List courseList); public void emptyList(); Now create one more class in the ca.whatevercollege..repositories package called CourseListImpl which implements CourseList. Add an @Component annotation above your CourseListImpl class. This tells Spring it is an actively managed component of our application, and so Spring should instantiate it and set the instance aside in an Inversion of Control container until it needs one. Inside CourseListImpl, create a new private List of Course as an ArrayList as follows: private List courseList = new CopyOnWriteArrayList(); A CopyOnWriteArrayList is a type of List. In fact, List itself is just an Interface, and CopyOnWriteArrayList is a possible implementation of it. Why CopyOnWriteArrayList you ask? The CopyOnWriteArrayList isdesigned to be Thread safe, so if we have hundreds or thousands of folks reading and writing from/to it at the same time, they won’t get into each other’s way. Generate getters and setters as before. If you’ve typed it correctly, the new methods should line up exactly with the signatures from your interface. As a helpful hint, I’ll give you the emptyList method too! public void emptyList() { courseList.clear(); } List into a regular old interface List. As an ArrayList is a more specific type of List, but is still everything our List is – it conforms to the List interface perfectly! – it fits in the hole! Cool you say, but what about injection?! When dependency injection is done properly, it follows many of the same principles... In your CourseController, add the following property: private CourseList courseList; and annotate it with @Autowired annotation. In your processForm method, create a new instance of Course using the Request Params and your overloaded constructor, then add your Course to your repository, then print the full list, as follows: Course course = new Course(id, prefix, code, name); courseList.getCourseList().add(course); System.out.println the quotes in Word and PowerPoint rarely copy correctly – be careful! for (Course c : courseList.getCourseList()) { System.out.println(c); } Now run it! Add a few courses from your form and check out your console! Cool! Where, you may ask, did our CourseListImpl instance that fills in the CourseList shaped hole come from? *It was injected by Spring! Automatically!Because we annotated our code with Spring Boot functionality (@Component and @Autowired in this case),

support
close