当我尝试POST方法时,我总是收到以下错误:
{" status":405 "错误":"方法不允许" "例外":" org.springframework.web.HttpRequestMethodNotSupportedException" "消息":"请求方法' POST'不支持" "路径":" / api / items" }
@RepositoryRestController
@RequestMapping("/items")
public class ItemController {
private static final Logger LOGGER = LoggerFactory.getLogger(ItemController.class);
private final ItemService service;
@Autowired
public ItemController(ItemService service) {
this.service = service;
}
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
ItemDto create(@RequestBody @Valid ItemDto item) {
LOGGER.debug("Creating item={}", item);
return service.create(item);
}
}
@RepositoryRestResource()
public interface ItemRepository extends MongoRepository<Item, String> {}
@Service
public class ItemServiceImpl implements ItemService {
private static final Logger LOGGER = LoggerFactory.getLogger(ItemServiceImpl.class);
private final ItemRepository itemRepository;
@Autowired
public ItemServiceImpl(ItemRepository itemRepository) {
this.itemRepository = itemRepository;
}
@Override
public ItemDto create(ItemDto item) {
Date date = new Date(System.currentTimeMillis());
LOGGER.debug("Creating new item={}, date={}", item, date);
Item persisted = Item.getItemBuilder(item.getTitle(), item.getPrice(), item.getDescription())
.withCategory(item.getCategory())
.withOwner(item.getOwner())
.withPhotos(item.getPhotoURLs())
.withState(item.getState())
.withDate(date)
.build();
itemRepository.save(persisted);
return convertToDto(persisted);
}
你知道为什么以及如何解决它吗?提前致谢