Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want to run the below petition application but it now reads - I have to archive it as a war file using tomcat and

I want to run the below petition application but it now reads - I have to archive it as a war file using tomcat and deploy it. have jenkins pipeling running as will.

image text in transcribed

Why? how do I fix it?

Main - PetitionApplication

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); } }

PetitionController

package com.example.demo; import com.example.demo.Petition; import com.example.demo.Signature; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @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; } }

POMS

4.0.0 org.springframework.boot spring-boot-starter-parent 3.1.6 com.example demo 0.0.1-SNAPSHOT war example Petition project for Spring Boot 17 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat org.springframework.boot spring-boot-starter-test test ${project.artifactId} org.springframework.boot spring-boot-maven-plugin paketobuildpacks/builder-jammy-base:latest

Petition

package com.example.demo; import java.util.List; public class Petition { private static int idCounter = 1; private int id; private String title; private String content; private List signatures; public static int getIdCounter() { return idCounter; } public static void setIdCounter(int idCounter) { Petition.idCounter = idCounter; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public List getSignatures() { return signatures; } public void setSignatures(List signatures) { this.signatures = signatures; } }

ServletInitilizer

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); } }

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Dec 16 12:40:59 GMT 2023 There was an unexpected error (type=Not Found, status=404). Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Dec 16 12:40:59 GMT 2023 There was an unexpected error (type=Not Found, status=404)

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

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

=+-cach nonempty one contains a rational.

Answered: 1 week ago