I'm trying to save User data on database through Spring data JPA.Unfortunately when in my controller class I call RegistrazioneService it comes null.
registrazioneController.java : it's a normal JSF controller ...
@ManagedBean(name="registrazioneController")
@ViewScoped
public class RegistrazioneController {
private String username = "";
private String password = "";
private String repassword = "";
private String email;
@ManagedProperty(value = "#{registrazioneService}")
private RegistrazioneService registrazioneService;
public void registraUser() {
System.out.println("inizio registrazione utente...");
// si salva nel db il nuovo utente
User utente = new User();
utente.setUsername(username);
utente.setPassword(password);
utente.setEmail(email);
utente.setDataCreazione(new Date());
// di default si assegna all'utente il ruolo ROLE_USER
utente.setRole(Role.ROLE_USER);
registrazioneService.registraUtente(utente);
}
RegistrazioneService :
@Service
public class RegistrazioneService {
@Autowired
UserRepository userRespository;
@Transactional
public void registraUtente(User user) {
System.out.println(("sono in registraUtente()"));
userRespository.save(user);
}
}
and that's UserRepository :
@Repository
public interface UserRepository extends CrudRepository<User, Long> {
}
Can someone help me please?