Consider defining a bean of type 'service.CloudVendorService' in your configuration. This error is showing.
My project can be found here: https://github.com/binit1212/rest-demo
There are several layers, so some annotation must be missing.
I have a controller, model, repository, implementation, and service layer.
This my controller:
package com.thinkconstructive.restdemo.controller;
import com.thinkconstructive.restdemo.model.CloudVendor; import org.springframework.web.bind.annotation.*; import service.CloudVendorService;
import java.util.List;
@RequestMapping("/cloudvendor") @RestController
public class CloudVendorController { CloudVendorService cloudVendorService; public CloudVendorController(CloudVendorService cloudVendorService) { this.cloudVendorService = cloudVendorService; }
@GetMapping("{vendorId}") public CloudVendor getCloudVendorDetails(@PathVariable("vendorId") String vendorId){ return cloudVendorService.getCloudVendor(vendorId); } @GetMapping() public List<CloudVendor> getAllCloudVendorDetails(){ return cloudVendorService.getAllCloudVendors(); } @PostMapping public String createCloudVendorDetails(@RequestBody CloudVendor cloudVendor) { cloudVendorService.createCloudVendor(cloudVendor); return "Cloud Vendor created successfully"; } @PutMapping public String updateCloudVendorDetails(@RequestBody CloudVendor cloudVendor) { cloudVendorService.updateCloudVendor(cloudVendor); return "Cloud Vendor updated successfully"; } @DeleteMapping("/{vendorId}") public String deleteCloudVendorDetails(@PathVariable("vendorId") String vendorId) { cloudVendorService.deleteCloudVendor(vendorId); return "Cloud Vendor Deleted successfully"; }}
This is model class
package com.thinkconstructive.restdemo.model;
import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table;
@Entity @Table(name="cloud_vendor_info") public class CloudVendor { @Id public String getVendorId() { return vendorId; }
public void setVendorId(String vendorId) { this.vendorId = vendorId; } public String getVendorName() { return vendorName; } public void setVendorName(String vendorName) { this.vendorName = vendorName; } public String getVendorAddress() { return vendorAddress; } public void setVendorAddress(String vendorAddress) { this.vendorAddress = vendorAddress; } public String getVendorPhoneNumber() { return vendorPhoneNumber; } public void setVendorPhoneNumber(String vendorPhoneNumber) { this.vendorPhoneNumber = vendorPhoneNumber; } private String vendorId; private String vendorName; private String vendorAddress; private String vendorPhoneNumber; public CloudVendor() { } public CloudVendor(String vendorId, String vendorName, String vendorAddress, String vendorPhoneNumber) { this.vendorId = vendorId; this.vendorName = vendorName; this.vendorAddress = vendorAddress; this.vendorPhoneNumber = vendorPhoneNumber; }}
This is my repository:
package com.thinkconstructive.restdemo.repository;
import com.thinkconstructive.restdemo.model.CloudVendor; import org.springframework.data.jpa.repository.JpaRepository;
public interface CloudVendorRepository extends JpaRepository<CloudVendor, String> {
}
This is my package impl;
import com.thinkconstructive.restdemo.model.CloudVendor; import com.thinkconstructive.restdemo.repository.CloudVendorRepository; import org.springframework.stereotype.Service; import service.CloudVendorService;
import java.util.List;
@Service public class CloudVendorServiceImpl implements CloudVendorService {
CloudVendorRepository cloudVendorRepository; public CloudVendorServiceImpl(CloudVendorRepository cloudVendorRepository) { this.cloudVendorRepository = cloudVendorRepository; } @Override public String createCloudVendor(CloudVendor cloudVendor) { cloudVendorRepository.save(cloudVendor); return "Success"; } @Override public String updateCloudVendor(CloudVendor cloudVendor) { cloudVendorRepository.save(cloudVendor); return "Success"; } @Override public String deleteCloudVendor(String cloudVendorId) { cloudVendorRepository.deleteById(cloudVendorId); return "Success"; } @Override public CloudVendor getCloudVendor(String cloudVendorId) { return cloudVendorRepository.findById(cloudVendorId).get(); } @Override public List<CloudVendor> getAllCloudVendors() { return cloudVendorRepository.findAll(); }}
This is service layer:
package service; import com.thinkconstructive.restdemo.model.CloudVendor; import java.util.List; public interface CloudVendorService { public String createCloudVendor(CloudVendor cloudVendor); public String updateCloudVendor(CloudVendor cloudVendor); public String deleteCloudVendor(String cloudVendorId); public CloudVendor getCloudVendor(String cloudVendorId); public List<CloudVendor> getAllCloudVendors(); }