Avatar
1
Mathis Favier Beginner
Mathis Favier Beginner
[Easyfox-server] null pointer Exception on user repo while trying to connect
So I watched the <a href="https://www.youtube.com/watch?v=aTZDSiiITBM&amp;list=PLlZavoxtKE1IfKY7ohkLLyv6YkHMkvH6G&amp;index=4">video</a> for the authentication with Ezyfox-server but I got an NullPointerException on UserRepo while I try to log in. I can't figure out why because I triple check my code and the video... <p> </p> <p> Here is my code: </p> <p> </p> <pre> # entity/BullyUser: @Getter @Setter @ToString @EzyCollection public class BullyUser { @EzyId int id; String username; String password; } # repo/BullyUserRepo: @EzyRepository("userRepo") public interface BullyUserRepo extends EzyMongoRepository&lt;Long, BullyUser&gt; { } # service/BullyUserService: public interface BullyUserService { void saveUser(BullyUser user); BullyUser createUser(String username, String password); BullyUser getUser(String username); } # service/impl/BullyUserServiceImpl: @Setter @EzySingleton("userService") public class BullyUserServiceImpl implements BullyUserService { @EzyAutoBind private BullyUserRepo BullyUserRepo; @Override public void saveUser(BullyUser user) { BullyUserRepo.save(user); } @Override public BullyUser createUser(String username, String password) { BullyUser user = new BullyUser(); user.setUsername(username); user.setPassword(password); BullyUserRepo.save(user); return user; } @Override public BullyUser getUser(String username) { return BullyUserRepo.findByField("username", username); } } // [PLUGIN]/controller/UserLoginController @EzySingleton @EzyEventHandler(USER_LOGIN) public class UserLoginController extends EzyAbstractPluginEventController { @EzyAutoBind private WelcomeService welcomeService; @EzyAutoBind private BullyUserService userService; @Override public void handle(EzyPluginContext ctx, EzyUserLoginEvent event) { logger.info("{} login in", welcomeService.welcome(event.getUsername())); String username = event.getUsername(); String password = event.getPassword(); BullyUser user = userService.getUser(username); if (user == null) { logger.info("User {} does not exist, creating new user", username); user = userService.createUser(username, password); userService.saveUser(user); } } } </pre>
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
[Go]Khi nào thì nên dùng con trỏ?
Mình thấy go có kiểu con trỏ và không con trỏ, mình toàn dùng không con trỏ, vậy anh em hay dùng con trỏ cho trường hợp nào?
Answer