vendredi 23 octobre 2020

Can not access endpoint URL in Springboot Rest web project

I've Initialized a SpringBoot Rest in eclipse and made it a Dynamic Web project. A 3-tire principle has been followed and endpoint URLs declared in controller classes. The project deploys fine but once I try to access an endpoint that returns a 404-error. Please refer to the example below. Used Compiler - Maven and Server - apache tomcat 9.0

MainClass.java

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@SpringBootApplication
public class PmsAdvanced {

    public static void main(String[] args) {
        SpringApplication.run(PmsAdvanced.class, args);
    }
}

Sample Controller class

@RestController
@RequestMapping("/test")
@EnableAutoConfiguration
@Configuration
public class PmsAdvancedController implements WebMvcConfigurer {

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("/index.jsp");
    registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}

@PostMapping("/PMS")
public String sayHello(@RequestParam(value = "myName", defaultValue = "divi") String name) {
    return String.format("Hello %s!", name);
}

@GetMapping("/PMSA")
public String sayAge(@RequestParam(value = "age", defaultValue = "100") String age) {
    return String.format("I'm %s!", age);
}}

Aucun commentaire:

Enregistrer un commentaire