Kullanıcıların farklı depo türlerinde benzersiz öğeleri almalarını sağlayan bir web uygulaması yazıyorum. Denetleyici sınıfımda tanımlamaya çalıştığım 2 GET API uç noktası var.İlkbaharda sorunlu haritalama sorunu 2 benzer İstekKullanım yolları
Retrieve items related to a particular warehouse.
api-item/v1/items?warehouse="001"
Parameter: warehouse
Retrieve all items from all warehouses
api-item/v1/items
ItemController.java:
@RequestMapping(value = "/v1/items", method = RequestMethod.GET)
public ReturnResponse getItems() {
List <Product> itemsList = itemService.getItems();
return myDefinedUtilities.getHttpStatusResponse("success.items", HttpStatus.OK, itemsList, null);
}
@RequestMapping(value = "/v1/items", method = RequestMethod.GET)
public ReturnResponse getItemsForWarehouse(@RequestParam(required = true, value = "warehouse") String wareHouseId) {
List <Product> itemsList = itemService.getItemsForWarehouse(wareHouseId);
return myDefinedUtilities.getHttpStatusResponse("success.items", HttpStatus.OK, itemsList, null);
}
Ben hizmet sınıfı alay, benim JUnit test sınıfında bu 2 yöntemlerini test eden test yöntemleri tanımladığınız: itemService. RequestMapping
Ek açıklamanın
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at ....
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'itemController' method
public com.trinet.domain.common.ReturnResponse com.trinet.web.controller.product.itemController.getItemsForWarehouse(java.lang.String)
to {[/v1/items],methods=[GET]}: There is already 'itemController' bean method
public com.trinet.domain.common.ReturnResponse com.trinet.web.controller.product.itemController.getItems() mapped.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)...