We've a controller which looks like below:
@RestController()
public class TestController {
@Autowired
TestService testService;
....
// Update request
@PutMapping("/update")
public ResponseEntity<Sample> updateApi(@PathVariable(value = "id") Long id,
@Valid @RequestBody Sample sampleDetails) {
return new ResponseEntity<Sample>(testService.updateSample(id, sampleDetails), HttpStatus.OK);
}
....
Service class(which has dependency on JPA repository) looks like:
@Service
public class TestService {
@Autowired
TestRepository testRepository;
// update sample
public Api updateSample(long sampleId, Sample details) {
// Get object to be updated
Sample sample = apiRepository.findById(sampleId);
// Update required fields
sample.setName(details.getName());
sample.setBody(details.getBody());
return apiRepository.save(api);
}
- In the above service(TestService) setName and setBody method calls to jpa repository: Do these steps hold state(i.e not stateless) and can cause issue while handling concurrent requests. Or do we need to make scope of this service(or the updateSample method in service) as "web-aware Spring ApplicationContext"
- Similar to point 1, this line: "Sample sample = apiRepository.findById(sampleId);", Will this line be thread safe or can cause issue while handling concurrent requests.