我将 Undertow 作为一个简单的 Servlet 容器运行。我部署了 Resteasy servlet:
ResteasyDeployment restEasyDeployment = new ResteasyDeployment();
Reflections reflections = new Reflections("");
Set<Class<?>> resourceClassSet = reflections.getTypesAnnotatedWith(Path.class);
restEasyDeployment.getActualResourceClasses().addAll(resourceClassSet);
ServletInfo servletInfo = Servlets.servlet("RestEasyServlet", HttpServlet30Dispatcher.class);
servletInfo.setAsyncSupported(true)
.setLoadOnStartup(1)
.addMapping("/*");
DeploymentInfo deploymentInfo = new DeploymentInfo();
deploymentInfo.setContextPath(path)
.addServletContextAttribute(ResteasyDeployment.class.getName(), restEasyDeployment)
.addServlet(servletInfo)
.setDeploymentName("api")
.setClassLoader(ClassLoader.getSystemClassLoader());
DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(deploymentInfo);
deploymentManager.deploy();
如何为 Resteasy 内部部署的资源提供任何构造参数?
我看到使用静态字段的教程,但我想保持依赖倒置以便于测试。在 Servlet 世界中,正确的做法是将所有内容放在上下文中。