[英]Getting 404 error when try to resttemplate getforobject
I have catalog service that works with product service to get data (microservices).我有与产品服务一起使用以获取数据(微服务)的目录服务。 When I try to make getForObject in catalog service, I have an error 404.当我尝试在目录服务中创建 getForObject 时,出现错误 404。
@RestController
@RequestMapping("/catalog")
public class ProductCatalogApi {
@Autowired
private RestTemplate restTemplate;
@GetMapping("")
public String hello(){
return "Heelloooo";
}
@GetMapping("/{category}")
public void getProductsByCategoryName(@PathVariable String category) {
UserProduct userProduct = restTemplate.getForObject(
"http://shop-product-service/shop/products" + category,
UserProduct.class);
System.out.println("dsdasa--------"+ userProduct);
}
This is my product service:这是我的产品服务:
@RestController
@RequestMapping("/shop")
public class ProductController {
@Autowired
ProductRepository productRepository;
@GetMapping("/all")
public List<Product> index(){
return productRepository.findAll();
}
@GetMapping("/product/{id_product}")
public Optional<Product> showByProductId(@PathVariable String id_product){
return productRepository.findById(id_product);
}
@GetMapping("/products/{category}")
public List<Product> showByCategoryName(@PathVariable String category){
return productRepository.findByCategory(category);
}
}
So when I try to make link this: http://localhost:8082/catalog/electronics , I get error, Please help me.因此,当我尝试创建链接时: http://localhost:8082/catalog/electronics ,我收到错误,请帮助我。
you lost the character "/" in the class ProductCatalogApi:您在 class ProductCatalogApi 中丢失了字符“/”:
restTemplate.getForObject(" http://shop-product-service/shop/products " + category, UserProduct.class); restTemplate.getForObject(" http://shop-product-service/shop/products " + category, UserProduct.class);
http://shop-product-service/shop/products => http://shop-product-service/shop/products/ http://shop-product-service/shop/products => http://shop-product-service/shop/products/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.