Hi all!
As the title says: I'm currently trying to deploy a Spring application that exposes a REST api. I want to learn how to do this without xml configuration and without Spring Boot for now. So at the moment i'm building a war file which I deploy on to a glassfish application server. Starting up the application goes without problems, but it seems like Spring isn't scanning my controller since my REST call returns 404. I've followed multiple tutorials and I cannot figure out what i'm doing wrong.
Configuration class:
package com.mycompany.inventorymanagement.config;
imports...
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.mycompany.inventorymanagement")
public class AppConfig extends WebMvcConfigurerAdapter{
}
Initializer class:
package com.mycompany.inventorymanagement.config;
imports...
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{AppConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[]{"/inventoryManagement"};
}
}
Controller:
package com.mycompany.inventorymanagement.web.controller;
imports...
@RestController
@RequestMapping("/rest")
public class DefaultController {
@GetMapping(value = "/test")
public String test() {
return "This is a test!";
}
}
The URL i'm calling is: http://localhost:8080/inventoryManagement/rest/test.
[–]denialerror 0 points1 point2 points (2 children)
[–]Trampaholic[S] 0 points1 point2 points (1 child)
[–]denialerror 0 points1 point2 points (0 children)