Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

See below code Asked to write a petition application. It needs to go through Jenkins pipeline, be packaged in a .war file and be deployed

See below code Asked to write a petition application. It needs to go through Jenkins pipeline, be packaged in a .war file and be deployed in a tomcat container through EC2. When I added the Tomcat dependencies and archives in POMS the application stopped working. Why?

Thanks for the help. Should be no URLs

Main Petition application

package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class PetitionApplication { public static void main(String[] args) { SpringApplication.run(PetitionApplication.class, args); } }

Petition Controller

package com.example.demo; import com.example.demo.Petition; import com.example.demo.Signature; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.boot.SpringApplication; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @SpringBootApplication @Controller public class PetitionController { private List petitions = new ArrayList<>(); @GetMapping("/") public String redirectToPetitions() { return "redirect:/petitions"; } @GetMapping("/petitions") public String viewPetitions(Model model) { model.addAttribute("petitions", petitions); return "view_petitions"; } @GetMapping("/petitions/create") public String createPetitionForm(Model model) { model.addAttribute("petition", new Petition()); return "create_petition"; } @PostMapping("/petitions/create") public String createPetition(@ModelAttribute Petition petition) { petition.setId(Petition.getIdCounter()); Petition.setIdCounter(Petition.getIdCounter() + 1); petition.setSignatures(new ArrayList<>()); petitions.add(petition); return "redirect:/petitions"; } @GetMapping("/petitions/search") public String searchPetitionForm() { return "search_petition"; } @PostMapping("/petitions/search") public String searchPetition(@RequestParam String keyword, Model model) { List searchResults = petitions.stream() .filter(p -> p.getTitle().contains(keyword) || p.getContent().contains(keyword)) .collect(Collectors.toList()); model.addAttribute("searchResults", searchResults); return "search_result"; } @GetMapping("/petitions/{id}") public String viewPetition(@PathVariable int id, Model model) { Petition petition = petitions.stream() .filter(p -> p.getId() == id) .findFirst() .orElse(null); if (petition != null) { model.addAttribute("petition", petition); model.addAttribute("signature", new Signature()); return "view_petition"; } else { return "redirect:/petitions"; } } @PostMapping("/petitions/{id}/sign") public String signPetition(@PathVariable int id, @ModelAttribute Signature signature) { Petition petition = petitions.stream() .filter(p -> p.getId() == id) .findFirst() .orElse(null); if (petition != null) { petition.getSignatures().add(signature); } return "redirect:/petitions/" + id; } }

ServletInitlizer

package com.example.demo; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(PetitionApplication.class); } }

POMS

"1.0" encoding="UTF-8"?>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+26.14. 1 Show that y has no point masses if 2(t) is integrable.

Answered: 1 week ago

Question

Draw a schematic diagram of I.C. engines and name the parts.

Answered: 1 week ago