Мне нужно использовать @Service из другого проекта Spring. Мне понадобится вызов REST, чтобы вызвать его, но как мне это сделать? Это сервис:
@Service
public class LocationsService implements ILocationsService {
private final Logger logger = LoggerFactory.getLogger("LocationsService");
private final ILocationRepository locationRepository;
private final IEvseRepository evseRepository;
private final IConnectorRepository connectorRepository;
@PersistenceContext
private EntityManager entityManager;
@Autowired
public LocationsService(ILocationRepository locationRepository, IEvseRepository evseRepository, IConnectorRepository connectorRepository, EntityManager entityManager) {
this.locationRepository = locationRepository;
this.evseRepository = evseRepository;
this.connectorRepository = connectorRepository;
this.entityManager = entityManager;
}
public Location getLocation(String countryCode, String partyId, String id) {
return locationRepository.findByCountryCodeAndPartyIdAndId(countryCode, partyId, id);
}
public Location deleteLocation(String countryCode, String partyId, String id) {
Location location = locationRepository.findByCountryCodeAndPartyIdAndId(countryCode, partyId, id);
if (location == null) {
logger.info("Location does not exist.");
return null;
}
locationRepository.deleteById(location.getLocId());
return location;
}
Мне нужно вызвать сервис на этом контроллере. Контроллер находится в другом проекте:
@RestController
@RequestMapping(value = "/locations", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(tags = "Locations management")
public class LocationController {
@Autowired
private LocationsService locationsService;
@RequestMapping(method = RequestMethod.GET , produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get Locations", notes = "Get locations", nickname = "getLocations",
authorizations = @Authorization(value = "Bearer"))
public ResponseEntity<List<LocationDto>> getLocations() {
List<LocationDto> locations = new ArrayList<>();
return new ResponseEntity<>(locations, HttpStatus.OK);
}
}
Я искал решения, но не нашел ничего полезного и буду признателен за любую помощь. Спасибо!