
ProductController calls InventoryController to fetch inventory by product id. Here we will show how to use the inventory controller client to support service to service calls.
Perform the steps described in section Config Data Source as you did for the other services.
To set the service port (the default port 8080 has been taken by OrderController), open the application.properties file and add the property server.port=8082
Open the file src/main/java/com/oms/productcontroller/ProductControllerApp.java and add the annotation @EntityScan("com.oms.entity") and @ComponentScan("com.oms")with the required import to the application class as you did for Order Controller.
In the ProductService class, change the import statement: import javax.transaction.Transactional; to: import jakarta.transaction.Transactional;
Open the class com.oms.service.ProductService. You should see errors related to InventoryService since there is no such class in ProductController
Open the pom.xml file of ProductController and add the dependency InventoryController-client
<dependency>
<groupId>com.oms</groupId>
<artifactId>InventoryController-client</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>Go back to ProductService.java and remove the inventoryService member along with all references to it (getter and setter)
Go to getProductInventory and change the implementation to use the inventory controller client:
public Inventory getProductInventory(String pid) {
logger.log(this.getClass().getName());
Inventory inv = null;
try {
InventoryService inventorySerice = new InventoryService("http://localhost:8081/inventoryService");
inv = inventorySerice.fetchInventory(pid);
} catch (IOException e) {
e.printStackTrace();
}
return inv;
}If needed add the import statement import com.oms.inventorycontroller.InventoryService; (you can also use quick fix in VS Code)
Remove the import of com.oms.entity.ShippingService and any other code elements referencing ShippingService, as this was marked as dead-code in the analysis
In AmazonQ or CoPilot run the following prompt in a new chat:
@Workspace migrate product-controller to Java 17 and to the latest SpringBoot 3
(make sure to respond when prompted by the agent)
Compile the ProductController service (Maven clean and then Maven install). Note: you may need to run spotless to re-arrange the imports (mvn spotless:apply)
Run the OrderController service from the spring boot dashboard in VS Code (if not already running) and create orders lines by sending the request Create Multiple Orders from Postman
Run the InventoryController (if not already running) and create inventory items by sending the request Create Multiple Inventory Items from Postman
Copy the file products-requests.http from the original git repository to the service folder
copy c:\vFunctionLab\oms-tutorial\oms-services\products-requests.http c:\vFunctionLab\oms-services\product-controller In VS Code, open the file products-requests.http and test the APIs by clicking Send Request above the various REST APIs calls
Optionally review the changes in the git view of VS Code and commit to your local git repo.
