0

I have tried all the solutions but I can´t fix this problem.

The classes that I have are:

  • User (Entity)
  • Negocio (Local interface EJB)
  • NegocioImpl (Stateless EJB with PersistenceContext)
  • Registro (Little @ManagedBean @RequestScoped to insert Users in DB with @PostConstruct init() method and @Inject attribute of Negocio and another attribute of User)

Here's the code of Registro:

import modelo.User;
import negocio.Negocio;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.inject.Inject;

@ManagedBean
@RequestScoped
public class Registro {

    @Inject
    private Negocio negocio;
    private User usuario;

    @PostConstruct
    public void init() {
        usuario = new User();
    }

    public User getUsuario() {
        return usuario;
    }

    public void setUsuario(User usuario) {
        this.usuario = usuario;
    }

    public void insertarUsuario() {
        negocio.sayHelloFromServiceBean(usuario);
    }

    public void saluda() {
        negocio.hola();
    }
}

Everything is apparently right. But when I test the application I have this exception:

enter image description here

Here is my web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
     version="3.1">
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>

Here is my faces-config.xml file:

<?xml version='1.0' encoding='UTF-8'?>

<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
              http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
          version="2.0">
</faces-config>

I'm using,

  • JSF 2.0
  • EJB 3.1
  • JBoss 7.1.1 Final
  • Java EE 6

with Intellij IDEA as IDE.

Thanks in advance

Tiny
  • 27,221
  • 105
  • 339
  • 599
Pepe Fernandez
  • 145
  • 1
  • 8
  • Looks like the EJB is not well injected, so not recognized inside the managed-bean. Try to inject it using `@EJB` annotation. – Omar Jun 26 '15 at 21:31
  • It's works!!!!!!! Thank's you! But I have a question, why whit @Inject is not working? – Pepe Fernandez Jun 27 '15 at 07:39
  • Please,next time don't post screenshots of stacktraces, post them as text – Kukeltje Jun 28 '15 at 07:06
  • @PepeFernandez, JSF and CDI are using the same annotations for scopes, but from different packages. We may say: `@Inject` goes with `@Named` for the managed-bean, while `@EJB` goes with `@ManagedBean` annotation, we shouldn't mix them. Take a look here : http://stackoverflow.com/questions/11986847/java-ee-6-javax-annotation-managedbean-vs-javax-inject-named-vs-javax-faces – Omar Jun 28 '15 at 12:29

0 Answers0