Reputation: 43
I'am trying to create a simple, annotation based rest service which have two distinct endpoints with endpoints specified by value of @RestController annotations. The problem is that the url provided in those annotations are ignored.
@RestController("/books")
public class BooksApi {
@RequestMapping("/getBook")
public String getBook() {
return "book";
}
@RestController("/movies")
public class MoviesApi {
@RequestMapping("/getMovie")
public String getMovie() {
return "movie";
}
}
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "application.webservices.apis")
public class ApiConfiguration {
}
public class ApisServletDispacher extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] {ApiConfiguration.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[0];
}
@Override
protected String[] getServletMappings() {
return new String[] {"/"};
}
}
So far the working url is: http://localhost:8080/getBook and I would like to have it changed to: http://localhost:8080/books/getBook
I'm running on wildfly 10, to war packaged application.
Why is xxx mapping in @RestController("XXX") ignored ?
Upvotes: 4
Views: 1086
Reputation: 8387
Try to use this:
@RestController
@RequestMapping("/books")
public class BooksApi {...
Upvotes: 3