我正在使用Spring Boot Web应用程序。我正在运行两个不同的应用程序服务(Rest Resource),另一个是UI,它根据其余请求的响应显示HTML页面上的请求。
我的所有休息服务都是由
创建的@Component
@Api(value = "/api/1/registration", description = "Access and manage your information")
@Path("/api/1/registration")
@Produces(MediaType.APPLICATION_JSON)
@Slf4j
public class RegistrationResource {
...
...
@ApiOperation(value = "Find user by id", notes = "Return a user by id", response = Registration.class)
@Path("/{id}")
@GET
@Timed
@Override
public Registration get(@PathParam("id") String id) {
// my logic
}
}
Restangular Request
Restangular.one("registration/1").get().then(function (data) {
...
},function(error) {
...
});
当我做ui的restangular请求时,它工作正常。现在我需要一个servlet资源。为此,我创建了新的资源类
@Slf4j
@RestController
@RequestMapping("/api/1/test")
public class DownloadResource{
@RequestMapping(value = "/downloadtesting", method = RequestMethod.GET)
public void download(HttpServletResponse response, HttpServletRequest request){
// I need to call this method... How can I
}
}
仅供参考:我的所有资源都注册如下......
Reflections reflections = new Reflections("com.sample.resource");
Set<Class<? extends Object>> resources =
reflections.getTypesAnnotatedWith(Path.class); //
resources.forEach(r -> {
log.debug("Registering resource " + r);
register(beanFactory.getBean(r));
});
//我也为RequestMapping.class做了同样的事情,但我在下载测试api时遇到404错误。
注意:如果我在RegistrationResource中尝试使用以下版本进行下载测试,那么我将获得HttpServletRequest / Response null。
public class RegistrationResource{
@Path("/downloadtesting")
public void download(HttpServletResponse response, HttpServletRequest request){
// I need to call this method... How can I
}
}
任何人都可以帮助我吗?