# 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<Long, BullyUser> {
}
# 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);
}
}
}
[Easyfox-server] null pointer Exception on user repo while trying to connect
video
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...
Here is my code:
ezyfox
question
pointer
issue
null
exception
Remain: 5
3 Answers
tvd12
Enlightened
tvd12
Enlightened
- Could you provide the error log?
- Are you sure you're setting up mongo database connection correctly?
- Are you sure you're using java 8 or java 11?
-
1
Mathis Favier
Beginner
Mathis Favier
Beginner
1/ the error log:
com.tvd12.ezyfoxserver.exception.EzyRequestHandleException: error when handle request from: Session#1(owner: null, address: /127.0.0.1:34930), command: LOGIN, data: [BullyServer, Arciesis, admin, []] at com.tvd12.ezyfoxserver.exception.EzyRequestHandleException.requestHandleException(EzyRequestHandleException.java:28) at com.tvd12.ezyfoxserver.handler.EzySimpleDataHandler.handleRequest(EzySimpleDataHandler.java:120) at com.tvd12.ezyfoxserver.handler.EzySimpleDataHandler.handleReceivedData(EzySimpleDataHandler.java:90) at com.tvd12.ezyfoxserver.handler.EzySimpleDataHandler.dataReceived(EzySimpleDataHandler.java:36) at com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioDataHandler.channelRead(EzySimpleNioDataHandler.java:19) at com.tvd12.ezyfoxserver.nio.handler.EzyAbstractHandlerGroup.fireChannelRead(EzyAbstractHandlerGroup.java:118) at com.tvd12.ezyfoxserver.socket.EzySocketRequestHandler.processRequest(EzySocketRequestHandler.java:69) at com.tvd12.ezyfoxserver.socket.EzySocketRequestHandler.handleEvent(EzySocketRequestHandler.java:30) at com.tvd12.ezyfoxserver.socket.EzySocketEventLoopOneHandler$1.doEventLoop(EzySocketEventLoopOneHandler.java:19) at com.tvd12.ezyfoxserver.socket.EzySimpleSocketEventLoop.eventLoop(EzySimpleSocketEventLoop.java:24) at java.lang.Thread.run(Thread.java:750) Caused by: java.lang.NullPointerException: null at xyz.beerocraft.BullyServer.common.service.impl.BullyUserServiceImpl.getUser(BullyUserServiceImpl.java:33) at xyz.beerocraft.BullyServer.plugin.controller.UserLoginController.handle(UserLoginController.java:34) at xyz.beerocraft.BullyServer.plugin.controller.UserLoginController.handle(UserLoginController.java:17) at com.tvd12.ezyfoxserver.context.EzyAbstractContext.handleEvent(EzyAbstractContext.java:78) at com.tvd12.ezyfoxserver.command.impl.EzyBroadcastPluginsEventImpl.firePluginEvent(EzyBroadcastPluginsEventImpl.java:60) at com.tvd12.ezyfoxserver.command.impl.EzyBroadcastPluginsEventImpl.fire(EzyBroadcastPluginsEventImpl.java:42) at com.tvd12.ezyfoxserver.context.EzySimpleZoneContext.broadcastPlugins(EzySimpleZoneContext.java:84) at com.tvd12.ezyfoxserver.controller.EzyLoginController.firePluginEvent(EzyLoginController.java:82) at com.tvd12.ezyfoxserver.controller.EzyLoginController.control(EzyLoginController.java:65) at com.tvd12.ezyfoxserver.controller.EzyLoginController.handle(EzyLoginController.java:33) at com.tvd12.ezyfoxserver.controller.EzyLoginController.handle(EzyLoginController.java:21) at com.tvd12.ezyfoxserver.handler.EzySimpleDataHandler.handleRequest(EzySimpleDataHandler.java:114) ... 9 common frames omitted
2/ I tested my connection to mongodb just before trying to login an user so my guess is that is not the problem
3/ I'm effectively using java 8 in my project !
It seems like there is a problem with the @EzySingleton tag in tghe UserLginController but I can't figure out why.
-
0
tvd12
Enlightened
tvd12
Enlightened
- you need use bullyUserRepo not BullyUserRepo
- you don't need specific name for a repo or service
- change file BullyServer-common-config.properties to application.properties?
- delete MongoDBConfig file
- read README.md to see how to deploy
-
0