Ola amigos, não sei se aconteceu com vcs mas eu tive problemas ao tentar injetar o UsuarioLogado no controller de login
tive a seguinte exception no console
SEVERE: Exception sending context initialized event to listener instance of class org.jboss.weld.environment.servlet.Listener
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UsuarioLogado with qualifiers @Default
at injection point [BackedAnnotatedParameter] Parameter 4 of [BackedAnnotatedConstructor] @Inject public br.com.caelum.vraptor.controller.LoginController(Validator, UsuarioDao, Result, UsuarioLogado)
at br.com.caelum.vraptor.controller.LoginController.<init>(LoginController.java:0)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:361)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:282)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:133)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:164)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:507)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
mar 15, 2016 7:51:19 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
mar 15, 2016 7:51:19 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/vraptor-produtos] startup failed due to previous errors
mar 15, 2016 7:51:19 PM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class org.jboss.weld.environment.servlet.Listener
java.lang.NullPointerException
at org.jboss.weld.servlet.WeldInitialListener.contextDestroyed(WeldInitialListener.java:102)
at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.contextDestroyed(ForwardingServletListener.java:30)
at org.jboss.weld.environment.servlet.Listener.contextDestroyed(Listener.java:85)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5115)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5779)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:224)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:159)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Meu controller esta igual ao feito na video aula(pelo menos eu acho...rs)
@Controller
public class LoginController {
private final Validator validator;
private final UsuarioDao dao;
private final Result result;
private final UsuarioLogado usuarioLogado;
@Inject
public LoginController(Validator validator,UsuarioDao dao,Result result,UsuarioLogado usuarioLogado) {
this.validator = validator;
this.dao = dao;
this.result = result;
this.usuarioLogado = usuarioLogado;
}
public LoginController() {
this(null,null,null,null);
}
@Get
public void formulario(){
}
@Post
public void autentica(Usuario usuario) {
if(!dao.existe(usuario)){
validator.add(new I18nMessage("login","login.invalido"));
validator.onErrorUsePageOf(this).formulario();
}
usuarioLogado.setUsuario(usuario);
result.redirectTo(ProdutoController.class).lista();
}
}
outra duvida que me surgiu foi a seguinte : a propiedade usuarioLogado esta setada como final, entao como é possivel setar valor nela após ela ja ter sido instanciada? desculpe se a pergunta foi idiota rs sou meio novato.
ah minha classe usuarioLogado:
@SessionScoped
@Named
public class UsuarioLogado implements Serializable{
private static final long serialVersionUID = 1L;
private Usuario usuario;
public Usuario getUsuario() {
return usuario;
}
public void setUsuario(Usuario usuario) {
this.usuario = usuario;
}
}