Unable to create managed bean

Posted on

Question :

I have a problem here in java that I do not know how to solve nor what it may be because I am learning to program with java for the web and I do not know the possible causes of the following error
javax.servlet.ServletException: Unable to create managed bean testeHibernate .

Used code


import java.util.List;

 import javax.faces.application.FacesMessage;
 import javax.faces.bean.ManagedBean;
 import javax.faces.bean.ManagedProperty;
 import javax.faces.bean.SessionScoped;
 import javax.faces.context.FacesContext;
 import Classhiber.Utilizador;
 import DAO.UtilizadorDAO;
 @ManagedBean(name = "testeHibernate" )
 public class testeHibernate {

private UtilizadorDAO utdao;

@ManagedProperty(value = "#{utiliza}")  
private Utilizador utiliza = new Utilizador();

public UtilizadorDAO getUtilizadorDAO() {
    return utdao;

public void setutilizador(UtilizadorDAO ut) {
    this.utdao = ut;

public Utilizador getutilizador() {
    return utiliza;

public void setutilizador(Utilizador utz) {
    this.utiliza = utz;

public String register() {
    // Calling Business Service
    // Add message
            new FacesMessage("The Employee "+this.utiliza.getUser()+" Is Registered Successfully"));
    return "";


 <?xml version="1.0" encoding="UTF-8"?>
    xmlns_xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns_aop="http://www.springframework.org/schema/aop"
    xsi_schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3307/xp" />
        <property name="username" value="root" />
        <property name="password" value="" />

<!-- Hibernate 4 SessionFactory Bean definition -->
<bean id="hibernate4AnnotatedSessionFactory"
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
        <property name="hibernateProperties">
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.current_session_context_class">thread</prop>
                <prop key="hibernate.show_sql">false</prop>

    <bean id="UtilizadorDAOimpl" class="Impl.UtilizadorDAOimpl">
        <property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />


<?xml version="1.0" encoding="UTF-8"?>
    xsi_schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns_xsi="http://www.w3.org/2001/XMLSchema-instance"
    id="WebApp_ID" version="2.5" metadata-complete="true">
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-name>Faces Servlet</servlet-name>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>

error – > It happens when I run the project on Tomcat-v7

javax.servlet.ServletException: Unable to create managed bean testeHibernate.  The following problems were found:
     - Property utiliza for managed bean testeHibernate does not exist.  Check that appropriate getter and/or setter methods exist.

Thank you.


Answer :

The cause of the error is this:

 - Property utiliza for managed bean testeHibernate does not exist. Check that appropriate getter and/or setter methods exist. 

You need to rename the getters/setters of the property you use. You have the methods setutilizador and getutilizador which arrow / returns the value of the property it uses. Rename them to setUtiliza and getUtiliza .

Whenever you make a get or set method … adopt this pattern: setValueName, starting with a capital letter after the set or get. Another thing is the class name starts with a capital letter.

Try to follow Oracle’s naming standards to facilitate the development of your programs as well as the maintenance and evolution thereof.


This is wrong: @ManagedProperty(value = "#{utiliza}")
It should look like this: @ManagedProperty(value = "utiliza")

The value that will be the “name” of the property you should only put its name (which in this case is "utiliza" ). This way #{utiliza} is just the syntax used by JSF to access the property defined in ManagedBean .



I do not see the need to use @ManagedProperty since you will not “change the property name” from uses to another name. Annotating Bean as @ManagedBean you can already access the properties of that have the get method as #{testeHibernate.nomeDaPropriedade} in JSF. Even if you have a method getSoma( ) but do not have a sum property in your Bean, if you access it by JSF #{testeHibernate.soma} it will call the getSoma() .


@ManagedBean(name = "testeHibernate" ) this attribute name is used to give the name of your Bean that will be accessed in JSF. By default, if you do not put the name parameter, it creates its name by copying the class name and by entering the first lowercase letter . Just put @ManagedBean for it to do this. In your case it would be testeHibernate . So need to put the attribute name, only if you want to make explicit the name it will receive , which I see as good practice too.


Leave a Reply

Your email address will not be published. Required fields are marked *