I know there are already tons of questions on this. But they don't clarify my doubts.
It is recommended here that to achieve thread safety, design your beans stateless. I don't understand it.
If I have a service class and it has only one state in it (and no other instance variables).
@Service
class MyService {
@Autowired
MyRepository repository;
//business method that call repository methods
}
MyRepository
has a default singleton scope. It has org.springframework.data.mongodb.core.MongoTemplate
autowired. And that's the only instance variable I have in MyReporitory
.
@Repository
class MyRepository {
@Autowired
MongoTemplate mongo;
//methods that use MongoTemplate reference
}
So what is the deal here? Is service/repository thread safe?