Tenho um bean qualquer que preciso ter o IP na inicialização do mesmo. Porém dá um erro indicando que não é possível injetar HttpServletRequest.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userSessionHolderInterceptor'
defined in file [esim.web.session.UserSessionHolderInterceptor.class]: Unsatisfied dependency expressed through constructor
argument with index 0 of type [esim.web.session.UserSession]:
java.rmi.RemoteException: null; nested exception is:
javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean;
@Component
@SessionScoped
public class UserSession
implements Serializable {
private final UserCredential myCredential;
public UserSession(HttpServletRequest request)
throws PolicyContextException {
final AuthenticationService service = ServiceLocator.getEJB(AuthenticationService.class);
myCredential = service.postJaasAuthentication(request.getUserPrincipal().getName(), request.getRemoteAddr());
}
@PreDestroy
public void destroy()
throws PolicyContextException {
ServiceLocator.getEJB(AuthenticationService.class).unauthenticate(myCredential.getEmail());
}
}
public class UserSessionHolderInterceptor
implements Interceptor {
private final UserSession userSession;
public UserSessionHolderInterceptor(UserSession userSession) {
this.userSession = userSession;
}
@Override
public boolean accepts(ResourceMethod method) {
return true;
}
@Override
public void intercept(InterceptorStack stack, ResourceMethod method, Object object)
throws InterceptionException {
[...]
stack.next(method, object);
}
}
