我试图扩展JHipster用户,所以我遵循以下官方教程:
http://www.jhipster.tech/tips/022_tip_registering_user_with_additional_information.html
重点是我总是在UserService.java
中出错UserService.java:[61,5]变量alRepository可能没有 初始化
下面你可以看到UserService.java代码。
inicial
$htmlContent = '
<html><body>
<h2>Title</h2>
<hr>
<p style="font-family:sans-serif;">
<b>Name: </b> (%s) <br>
<b>Email: </b> (%s) <br>
<b>Message: </b> (%s) <br>
</p>
</body></html>';
$htmlContent = sprintf($htmlContent, $name, $email, $message);
createUser方法
package br.ufrj.g2matricula.service;
import br.ufrj.g2matricula.domain.Authority;
import br.ufrj.g2matricula.domain.User;
import br.ufrj.g2matricula.domain.Aluno;
import br.ufrj.g2matricula.repository.AuthorityRepository;
import br.ufrj.g2matricula.config.Constants;
import br.ufrj.g2matricula.repository.UserRepository;
import br.ufrj.g2matricula.repository.AlunoRepository;
import br.ufrj.g2matricula.repository.search.UserSearchRepository;
import br.ufrj.g2matricula.repository.search.AlunoSearchRepository;
import br.ufrj.g2matricula.security.AuthoritiesConstants;
import br.ufrj.g2matricula.security.SecurityUtils;
import br.ufrj.g2matricula.service.util.RandomUtil;
import br.ufrj.g2matricula.service.dto.UserDTO;
import br.ufrj.g2matricula.web.rest.vm.ManagedUserVM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
/**
* Service class for managing users.
*/
@Service
@Transactional
public class UserService {
private final Logger log = LoggerFactory.getLogger(UserService.class);
private final UserRepository userRepository;
private final AlunoRepository alRepository;
private final PasswordEncoder passwordEncoder;
private final UserSearchRepository userSearchRepository;
private final AlunoSearchRepository alSearchRepository;
private final AuthorityRepository authorityRepository;
public UserService(UserRepository userRepository, PasswordEncoder passwordEncoder, UserSearchRepository userSearchRepository, AuthorityRepository authorityRepository) {
this.userRepository = userRepository;
this.passwordEncoder = passwordEncoder;
this.userSearchRepository = userSearchRepository;
this.authorityRepository = authorityRepository;
}
/*public UserService(UserRepository userRepository, AlunoRepository alunoRepository, PasswordEncoder passwordEncoder, UserSearchRepository userSearchRepository, AuthorityRepository authorityRepository) {
this.userRepository = userRepository;
this.passwordEncoder = passwordEncoder;
this.userSearchRepository = userSearchRepository;
this.authorityRepository = authorityRepository;
this.alRepository = alunoRepository;
}*/
我不能只设置alRepository = new AlunoRepository(),因为AlunoRepository是一个抽象类,无法实例化。
你们建议做什么?
答案 0 :(得分:2)
我想你忘记在你的userservice构造函数中注入alrepository bean了