Context
I work on a web-app (using Play Framework) and I'm trying to migrate to traditional Servlet model with Spring MVC. I'd like to run in an embedded Jetty container alongs an already existing one (netty).
Problem
I'm trying to re-use a created Spring context (that contains all application beans, including newly-added Spring MVC controllers), but the request mappings aren't picked up.
I debugged Spring's Dispatcher Servlet and there were no mappings registered indeed (so it could handle no path).
Attempted solution
Here's the manual Jetty setup code:
@RequiredArgsConstructor
public class EmbeddedJetty {
private final int port;
private final AnnotationConfigWebApplicationContext existingContext;
@SneakyThrows
public void start() {
Assert.notNull(existingContext.getBean(UserController.class));
val server = new Server(port);
ServletContextHandler handler = new ServletContextHandler();
ServletHolder servlet = new ServletHolder(new DispatcherServlet(existingContext));
handler.addServlet(servlet, "/");
handler.addEventListener(new ContextLoaderListener(existingContext));
server.setHandler(handler);
server.start();
log.info("Server started at port {}", port);
}
}
And here's the controller being ignored:
@Controller
public class UserController {
@GetMapping("/users/{userId}")
public ResponseEntity<?> getUser(@PathVariable("userId") long userId) {
return ResponseEntity.ok("I work");
}
}
Question
What do I needed to do to make my embedded jetty setup pick up the existing controller beans and serve the mappings?