0
@Autowired is the same as extends?
Let’s take a small example:
package com.dendetech.services;
import com.dendetech.Entity.Participant; import com.dendetech.repositories.Participanterepository; import org.springframework.Beans.factory.Annotation.Autowired; import org.springframework.stereotype.Service;
@Service public class Participanteservice {
@Autowired
private ParticipanteRepository participanteRepository;
/*
* Crud Operations
*/
<(Remainder omitted). >
On the line: >"@Autowired private Participantepository participantRepository;" Is the participating variable receiving the instance of the Participanterepository class object? Another question, it means that being the instantiated object in the Participanterepository class, I can use it in the service via @Autowired, as it is not possible to use an instantiated object elsewhere in the code?
– André Nascimento
1 - Yes, in this line and variable it takes the instance of the class autamticamente. 2 - The object will be instantiated in the class that is declared. In this case it is declared within the Participanteservice class. If you need this instance elsewhere, you can enter public getter methods to then call parrticipanteService.getParticipanteRepository(). It does not make much sense to use this second way. In case of doubts post on another question.
– Shura16