AppInitailizer.java
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{AppConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[]{"/api/*"};
}
}
AppConfig.java
@Configuration
@ComponentScan
@EnableWebMvc
public class AppConfig {
}
UserController.java
@RestController
@RequestMapping("/users")
public class UserController {
@Autowired
private UserService userService;
@RequestMapping(method = RequestMethod.GET)
public List<User> getUsers(){
List<User> users = userService.findAll();
return users;
}
When I tried to fire http://localhost:8080/practise/api/users, it results in "HTTP Status 404" - /practice/api/users (where practice is project name). In getServletMappings(), I gave the path as /api/* and UserController class has request mapping as /users. I dont know where I got wrong. When I access index.xml, it is working fine.
Screenshot of error:
Error on the browser when I try to access the api of application