[英]Getting null pointer exception in java spring hibernate app
I have class Registration with username email password 我有使用用户名电子邮件密码注册的课程
I have following function in dao , service classes 我在dao服务类中具有以下功能
public Registration get( Integer id ) {
logger.debug("Getting person");
return registrationDAO.findUserByID(id);
}
@Resource(name="registrationService")
private RegistrationService registrationService;
public Registration findUserByID(Integer ID) {
try {
Session session = sessionFactory.getCurrentSession();
Registration person = (Registration) session.get(Registration.class, ID);
return person;
} catch (Exception e) {
System.out.println(e);
throw new RuntimeException("DAO failed", e);
}
}
I am using that function in following function 我在以下功能中使用该功能
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
// Declare a null Spring User
UserDetails user = null;
logger.debug(username);
//for testing -- i get error here
Registration regUser = registrationService.get(1);
logger.debug(regUser);
try {
DbUser dbUser = userDAO.searchDatabase(username);
I get error when i add this line 添加此行时出现错误
Registration regUser = registrationService.get(1);
logger.debug(regUser);
Edit: For clarified question 编辑:对于澄清的问题
@Resource
private RegistrationService registrationService;
See the tutorial at: http://download.oracle.com/javaee/5/tutorial/doc/bncjk.html#bncjl 请参见以下教程: http : //download.oracle.com/javaee/5/tutorial/doc/bncjk.html#bncjl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.