When I added java-melody starter dependency on my spring boot application, it throws null pointer exception whenever i try to access the application.
I added this dependency in my pom file
<dependency>
<groupId>net.bull.javamelody</groupId>
<artifactId>javamelody-spring-boot-starter</artifactId>
<version>1.92.0</version>
</dependency>
And the application throws error at validationService as Null pointer This is my AuthenticationService class
@Slf4j
@Service
public class AuthenticationService implements IAuthenticationService {
@Autowired
private ValidationService validationService;
@Autowired
private UserLoginDao userLoginDao;
public TempLoginModel doSoftLogin(@Valid UserLoginRequest request) {
UserLogin userLogin = userLoginDao.findByUsernameAndCorporateCode(request.getUsername())
.orElseThrow(() -> new UsernameNotFoundException(
env.getProperty("message.authentication.service.wrong.credential")));
validationService.exceptionIfUserLoginNotActivated
.andThen(validationService.exceptionIfUserLoginLocked)
.accept(userLogin);
String jwtToken = JWTUtil.createJwt(request.getUsername(),
userLogin.getUserInformation().getMobileNumber());
return new TempLoginModel(jwtToken);
}
}
My validationService class is as
@Slf4j
@Service
public class ValidationService {
public Consumer<UserLogin> exceptionIfUserLoginNotActivated = (user) -> {
if (!user.isActivated()) {
throw new NoAccessException(env.getProperty("message.user.login.not.activate"));
}
};
public Consumer<UserLogin> exceptionIfUserLoginLocked = (user) -> {
if (user.getWrongLoginAttempt() >= getWrongPasswordAttemptCount()) {
throw new NoAccessException(env.getProperty("message.user.login.locked"));
}
};
}
I have a controller which directly calls the authenticationService
The exception is thrown as
java.lang.NullPointerException: null
at com.java.corporate.service.impl.AuthenticationService.exceptionIfInvalidLogin(AuthenticationService.java:355)
at com.java.corporate.service.impl.AuthenticationService.doSoftLogin(AuthenticationService.java:190)
at com.java.corporate.service.impl.AuthenticationService$$FastClassBySpringCGLIB$$1d9d9fd9.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at net.bull.javamelody.MonitoringSpringInterceptor.invoke(MonitoringSpringInterceptor.java:76)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
What additional configurations should be done for the java-melody monitoring to function properly?
My main method is
public TempLoginModel doSoftLogin(@Valid UserLoginRequest request) {
UserLogin userLogin = userLoginDao.findByUsername(request.getUsername())
.orElseThrow(() -> new UsernameNotFoundException(
env.getProperty("message.authentication.service.wrong.credential")));
exceptionIfInvalidLogin(request.getPassword(), userLogin);
}