- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试设计一个rest api,下面是我的 Controller 代码。
当我调用 http://localhost:8080/响应很好,但如果我点击 http://localhost:8080/api/ca它抛出 javax.servlet.ServletException: No adapter for handler [...CaDetailController@48224381]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
@RestController("/api")
public class CaDetailController {
private static final Logger logger = LoggerFactory.getLogger(GetClassLoader.class.getClass());
@Autowired
CaService caService;
@RequestMapping(path = "/ca", method = RequestMethod.GET)
public @ResponseBody List<CaDetail> getCorporateActions() {
logger.info("CaDetailController.findAllCaDetails()");
return caService.findAllCaDetails();
}
@RequestMapping(path = "/ca/{caId}", method = RequestMethod.GET)
public @ResponseBody List<CaDetail> getCorporateActions(@PathParam("caId") long caId) {
logger.info("CaDetailController.getCorporateActions() : caId : " + caId);
return caService.findAllCaDetails();
}
}
Updated controller.
@RestController
@RequestMapping("/api/ca")
public class CaDetailController {
private static final Logger logger = LoggerFactory.getLogger(GetClassLoader.class.getClass());
@Autowired
CaService caService;
@GetMapping(path = "/")
public @ResponseBody List<CaDetail> getCorporateActions() {
logger.info("CaDetailController.findAllCaDetails()");
return caService.findAllCaDetails();
}
@GetMapping(path = "/{caId}")
public @ResponseBody List<CaDetail> getCorporateActions(@PathParam("caId") Long caId) {
logger.info("CaDetailController.getCorporateActions() : caId : " + caId);
return caService.findAllCaDetails();
}
}
最佳答案
为清楚起见,修复是:
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/ca")
public class CaDetailController {
@GetMapping
public String healthcheck1() {
return "ok!";
}
@GetMapping(path = "health")
public String healthcheck2() {
return "ok again!";
}
}
关于spring-boot - DispatcherServlet 配置需要包含一个支持这个处理程序的 HandlerAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54802028/
我想在 Spring MVC 中同时使用注解映射和 xml 映射。我的application-context.xml如下:
我正在尝试设计一个rest api,下面是我的 Controller 代码。 当我调用 http://localhost:8080/响应很好,但如果我点击 http://localhost:8080/
厌倦了使用 XML 文件进行 Spring 配置,尝试转向完整的 Java 方法,但我无疑失败了。 只涉及 2 个类: @Configuration public class AppInitializ
我一直在阅读 Spring MVC HandlerMapping 和 HandlerAdapter 但是我对这两个概念感到困惑。我可以理解使用 HandlerMapping将传入的 HTTP 请求映射
我正在尝试基本的 Spring MVC 教程并遇到以下错误 - javax.servlet.ServletException: No adapter for handler [com.srs.spri
我目前正在使用 Spring MVC 的 HandlerAdapter 来测试我的 Spring Controller 操作的注释,以确保正确编写路径变量、请求参数、 session 属性、@Vali
大家好,因为这是我的 Controller 类,当我在 postman 中运行此应用程序时,它的显示状态为 200 ok。但是文件未读取,我如何将带有扩展名的文件名作为方法中的字符串参数传递?我缺少您
我是一名优秀的程序员,十分优秀!