From 18b869cab464aac790773b2bea93ee3378c5aede Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2026 15:09:05 +0000 Subject: [PATCH] Remove dead quote-service calls and modernize controller mappings for Spring Boot 3 Co-Authored-By: Amit Manchella --- src/main/java/hello/Application.java | 28 ++----------------- .../hello/controller/GreetingController.java | 4 +-- .../hello/controller/HelloController.java | 8 +++--- .../hello/controller/TopicController.java | 14 +++++----- 4 files changed, 16 insertions(+), 38 deletions(-) diff --git a/src/main/java/hello/Application.java b/src/main/java/hello/Application.java index 7cf8faf..f39364f 100644 --- a/src/main/java/hello/Application.java +++ b/src/main/java/hello/Application.java @@ -5,18 +5,14 @@ import java.util.stream.Collectors; import hello.model.Customer; -import hello.model.Quote; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.web.client.RestTemplate; @SpringBootApplication public class Application implements CommandLineRunner { @@ -34,25 +30,6 @@ public static void main(String[] args) { for (String beanName : beanNames) { System.out.println(beanName); } - - RestTemplate restTemplate = new RestTemplate(); - Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class); - log.info(quote.toString()); - } - - - @Bean - public RestTemplate restTemplate(RestTemplateBuilder builder) { - return builder.build(); - } - - @Bean - public CommandLineRunner run(RestTemplate restTemplate) throws Exception { - return args -> { - Quote quote = restTemplate.getForObject( - "http://gturnquist-quoters.cfapps.io/api/random", Quote.class); - log.info(quote.toString()); - }; } @@ -80,8 +57,9 @@ public void run(String... args) throws Exception { log.info("Querying for customer records where first_name = 'Josh':"); jdbcTemplate.query( - "SELECT id, first_name, last_name FROM customers WHERE first_name = ?", new Object[]{"Josh"}, - (rs, rowNum) -> new Customer(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name")) + "SELECT id, first_name, last_name FROM customers WHERE first_name = ?", + (rs, rowNum) -> new Customer(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name")), + "Josh" ).forEach(customer -> log.info(customer.toString())); } diff --git a/src/main/java/hello/controller/GreetingController.java b/src/main/java/hello/controller/GreetingController.java index cf52f8d..36ebdee 100644 --- a/src/main/java/hello/controller/GreetingController.java +++ b/src/main/java/hello/controller/GreetingController.java @@ -1,7 +1,7 @@ package hello.controller; import hello.model.Greeting; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -12,7 +12,7 @@ public class GreetingController { private static final String template = "Hello, %s!"; private final AtomicLong counter = new AtomicLong(); - @RequestMapping("/") + @GetMapping("/") public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) { return new Greeting(counter.incrementAndGet(), String.format(template, name)); diff --git a/src/main/java/hello/controller/HelloController.java b/src/main/java/hello/controller/HelloController.java index f3602fa..f706aa0 100644 --- a/src/main/java/hello/controller/HelloController.java +++ b/src/main/java/hello/controller/HelloController.java @@ -5,8 +5,8 @@ import hello.model.Topic; import hello.service.TopicService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.RequestMapping; import java.time.LocalDate; import java.time.LocalDateTime; @@ -43,7 +43,7 @@ public class HelloController { * * @return */ - @RequestMapping("/datetime") + @GetMapping("/datetime") public String index() { TimeClient myTimeClient = new SimpleTimeClient(); LocalDateTime localDateTime = LocalDateTime.now(); @@ -63,7 +63,7 @@ public String index() { * * @return */ - @RequestMapping("/topic/string/operation") + @GetMapping("/topic/string/operation") public String showStringOperation() { String join = topicService.returnAllTopicIDWithStringSlicing(); @@ -84,7 +84,7 @@ public String showStringOperation() { * File Operation in Java 8 * @return */ - @RequestMapping("/topic/file/operation") + @GetMapping("/topic/file/operation") public String showFileOperation() { String findAllFilesInPathAndSort = topicService.findAllFilesInPathAndSort(); String findParticularFileInPathAndSort = topicService.findParticularFileInPathAndSort(); diff --git a/src/main/java/hello/controller/TopicController.java b/src/main/java/hello/controller/TopicController.java index c2e8273..5e55dfa 100644 --- a/src/main/java/hello/controller/TopicController.java +++ b/src/main/java/hello/controller/TopicController.java @@ -18,7 +18,7 @@ public class TopicController { * Get all Topic * @return */ - @RequestMapping("/topic") + @GetMapping("/topic") public List getAllTopics() { return topicService.getAllTopics(); } @@ -28,7 +28,7 @@ public List getAllTopics() { * @param id * @return */ - @RequestMapping("/topic/{id}") + @GetMapping("/topic/{id}") public Topic getTopicWithID(@PathVariable String id) { return topicService.getTopicWithId(id); } @@ -37,7 +37,7 @@ public Topic getTopicWithID(@PathVariable String id) { * Add a new topic in list * @param topic */ - @RequestMapping(method = RequestMethod.POST, value = "/topic") + @PostMapping("/topic") public void addTopic(@RequestBody Topic topic) { topicService.addTopic(topic); } @@ -47,7 +47,7 @@ public void addTopic(@RequestBody Topic topic) { * @param id * @param topic */ - @RequestMapping(method = RequestMethod.PUT, value = "/topic/{id}") + @PutMapping("/topic/{id}") public void updateTopic(@PathVariable String id, @RequestBody Topic topic) { topicService.updateTopic(id, topic); } @@ -57,7 +57,7 @@ public void updateTopic(@PathVariable String id, @RequestBody Topic topic) { * Delete a topic with ID * @param id */ - @RequestMapping(method = RequestMethod.DELETE, value = "/topic/{id}") + @DeleteMapping("/topic/{id}") public void deleteTopic(@PathVariable String id) { topicService.deleteTopic(id); } @@ -67,7 +67,7 @@ public void deleteTopic(@PathVariable String id) { * @param minLength * @return */ - @RequestMapping(value = "/topic/minimum/length/{minLength}") + @GetMapping("/topic/minimum/length/{minLength}") public List filterMinimumLengthForId(@PathVariable Integer minLength) { return topicService.filterMinimumLengthForId(minLength); } @@ -77,7 +77,7 @@ public List filterMinimumLengthForId(@PathVariable Integer minLength) { * Sort with Id * @return */ - @RequestMapping("/topic/sort") + @GetMapping("/topic/sort") public List sortTopicsWithID() { return topicService.sortTopicsWithID(); }