私はspring mvcを使用して、残りのWebサービスを作成します。しかし、私はいつも404を手に入れます。どこが間違っているのか分かりません。ここで春RESTは常に戻る404
は私のイニシャライザである:ここでは
public class Initializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
// TODO Auto-generated method stub
return new Class<?>[] { RootConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
// TODO Auto-generated method stub
return new Class<?>[] { WebConfig.class };
}
@Override
protected String[] getServletMappings() {
// TODO Auto-generated method stub
return new String[] { "/" };
}
}
は私のWebConfigです:
@Configuration
@EnableWebMvc
@ComponentScan("com.jh.dummy.web")
public class WebConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResovler = new InternalResourceViewResolver();
viewResovler.setPrefix("/");
viewResovler.setSuffix(".html");
viewResovler.setExposeContextBeansAsAttributes(true);
return viewResovler;
}
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
ここに私の残りのサーバーファイルさ:
:@RestController
@RequestMapping("/v1/")
public class PositionService {
@RequestMapping(value = "position", consumes = MediaType.APPLICATION_JSON_VALUE, method = POST)
public void create(List<Map<String, String>> data) {
}
@RequestMapping(value = "position/{id:\\d+}", produces = MediaType.APPLICATION_JSON_VALUE, method = GET)
public void getById(@PathVariable("id") Long id) {
}
@RequestMapping(value = "position/title/{title:.+}/{start:\\d{1,}}", produces = MediaType.APPLICATION_JSON_VALUE, method = GET)
public void getByTitle(@PathVariable("title") String title,
@PathVariable("start") int start) {
}
@RequestMapping(value = "position/title/{title:.+}/address/{address:\\w{1,}}/{start:\\d{1,}}", produces = MediaType.APPLICATION_JSON_VALUE, method = GET)
public void getByTitleAndLocation(@PathVariable("title") String title,
@PathVariable("address") String address, @PathVariable("start") int start) {
}
@RequestMapping(value = "position/address/{address:\\w{1,}}/{start:\\d{1,}}", produces = MediaType.APPLICATION_JSON_VALUE, method = GET)
public void getByLocation(@PathVariable("address") String address,
@PathVariable("start") int start) {
}
@RequestMapping(value = "position/company/{company:.{1,}}/{start:\\d{1,}}", produces = MediaType.APPLICATION_JSON_VALUE, method = GET)
public void getByCompany(@PathVariable("company") String company,
@PathVariable("start") int start) {
}
}
ここでは、要求されます
私は、カールテストを使用すると、私はいつも404を取得します。どこがうまくいかないのはわかりません。何か案が?
完全なHTTPリクエストを確認できますか?ヘッダーを含める? –
@BoristheSpider HTTPリクエストは単純に「curl localhost:8080/v1/position/1」です。 –
ヘッダーが必要です。なぜなら、あなたが[Accept'ヘッダー](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)のために送るものを見る必要があるからです。 –