Я работаю над проектом Spring over Hibernate, я только в начале.Я пытаюсь иметь SpringBootApplication, который записывает в MySql некоторые объекты Location.Но каждый раз, когда я сталкиваюсь с какой-то ошибкой.Я сделал все с моей стороны, ссылаюсь, что все еще не могу решить это.Пожалуйста, помогите мне. Это моя ошибка
APPLICATION FAILED TO START
***************************
Description:
Field service in com.project.abhishek.location.controller.LocationController
required a bean of type'com.project.abhishek.location.service.LocationService' that could not be
found.
Action:
Consider defining a bean of type'com.project.abhishek.location.service.LocationService' in your configuration.
Класс приложения
@SpringBootApplication
@ComponentScan(basePackages= {"com.project.abhishek.location.controller"})
@EntityScan(value ="com.project.abhishek.location.entity")
@EnableJpaRepositories(basePackages = {"com.project.abhishek.location.repos"})
public class StudentApplication {
public static void main(String[] args) {
SpringApplication.run(StudentApplication.class, args);
}}
Контроллер
@Controller
public class LocationController {
@Autowired
private LocationService service;
@RequestMapping("/saveLoc")
public String saveLocation(@ModelAttribute("location") Location location, ModelMap modelMap) {
Location locationSaved = getService().saveLocation(location);
String msg = "Location save with id:" +locationSaved.getId();
modelMap.addAttribute("msg", msg);
return "createLocation";
}
public LocationService getService() {
return service;
}
public void setService(LocationService service) {
this.service = service;
}
Класс обслуживания
@Service
public class LocationServiceImpl implements LocationService {
@Autowired
private LocationRepos locationRepos;
@Override
public Location saveLocation(Location location) {
return locationRepos.save(location);
}
@Override
public Location updateLocation(Location location) {
return locationRepos.save(location);
}
@Override
public void deleteLocation(Location location) {
locationRepos.delete(location);
}
@Override
public Location getLocation(int id) {
Optional<Location> optional = locationRepos.findById(id);
Location location = optional.get();
return location;
}
@Override
public List<Location> getAllLocation() {
return locationRepos.findAll();
}
public LocationRepos getLocationRepos() {
return locationRepos;
}
public void setLocationRepos(LocationRepos locationRepos) {
this.locationRepos = locationRepos;
}
}
Сущность
@Entity
public class Location {
@Id
private int id;
private String code;
private String name;
private String type;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "Location [id=" + id + ", code=" + code + ", name=" + name + ", type=" + type + "]";
}
Мои пакетыструктура
com.project.abhishek.location---application classs
com.project.abhishek.location.controller---controller class
com.project.abhishek.location.entity---entity class
com.project.abhishek.location.repos---repository class
com.project.abhishek.location.service---service class