___ ___ erkimt error occurs when performing resource injection in Bean ______ qstntxt ___

Bean:

%pre%

Page:

%pre%

Exception:

  

javax.servlet.ServletException: An error occurred when performing resource injection on managed bean MBfabricantes       javax.faces.webapp.FacesServlet.service (FacesServlet.java:659)       org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:52)

    
______ ___ azszpr28385

The resolution of this was:

In the factory connections, specifically in the method, I put the following command (although my Java version is 7):

%pre%     
______ azszpr31582 ___

An additional to your own answer (This should be a comment, but strangely in some questions I am unable to comment (I am a new user)).

You make DriverManager.registerDriver (Driver driver) redundant. What was happening is that your application's DriverManager was not being notified to register the driver. See the static startup section of the com.mysql.jdbc.Driver class:

%pre%

Not that this is important, but it's the way JDBC Drivers work (they only need to be triggered once to be automatically registered). To avoid a strong direct coupling of your class with the driver, choose to do

%pre%

Usually on an application server, this code snippet is not required.

    
___

1

Bean:

package br.com.drogaria.bean;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.ListDataModel;
import br.com.drogaria.dao.FabricanteDAO;
import br.com.drogaria.domain.Fabricante;

@ManagedBean(name = "MBfabricantes")
@ViewScoped
public class FabricanteBean {
    private ListDataModel<Fabricante> fResultSearch;
    public ListDataModel<Fabricante> getfResultSearch() {
        return fResultSearch;
    }
    public void setfResultSearch(ListDataModel<Fabricante> fResultSearch) {
        this.fResultSearch = fResultSearch;
    }

    @PostConstruct
    public void catalogo() {
        FabricanteDAO fdao = new FabricanteDAO();

        try {
            ArrayList<Fabricante> list = fdao.listarTudo();
            fResultSearch = new ListDataModel<Fabricante>(list);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Page:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    template="/template/modeloSistema.xhtml">

    <ui:define name="menu">
        <ui:include src="/includes/menuPrincipal.xhtml" />
    </ui:define>

    <ui:define name="conteudo">
        <p:dataTable emptyMessage="Nada encontrado :("
            value="#{MBfabricantes.fResultSearch}" var="item">

            <p:column headerText="Código">
                <h:outputText value="#{item.codigo}" />
            </p:column>

            <p:column headerText="Descrição">
                <h:outputText value="#{item.descricao}" />
            </p:column>

        </p:dataTable>
    </ui:define>
</ui:composition>

Exception:

  

javax.servlet.ServletException: An error occurred when performing resource injection on managed bean MBfabricantes       javax.faces.webapp.FacesServlet.service (FacesServlet.java:659)       org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:52)

    
asked by anonymous 07.08.2014 / 07:08

2 answers

1
___ ___ erkimt error occurs when performing resource injection in Bean ______ qstntxt ___

Bean:

DriverManager.registerDriver(new com.mysql.jdbc.Driver());

Page:

DriverManager.registerDriver(new com.mysql.jdbc.Driver());

Exception:

  

javax.servlet.ServletException: An error occurred when performing resource injection on managed bean MBfabricantes       javax.faces.webapp.FacesServlet.service (FacesServlet.java:659)       org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:52)

    
______ ___ azszpr28385

The resolution of this was:

In the factory connections, specifically in the method, I put the following command (although my Java version is 7):

%pre%     
______ azszpr31582 ___

An additional to your own answer (This should be a comment, but strangely in some questions I am unable to comment (I am a new user)).

You make DriverManager.registerDriver (Driver driver) redundant. What was happening is that your application's DriverManager was not being notified to register the driver. See the static startup section of the com.mysql.jdbc.Driver class:

%pre%

Not that this is important, but it's the way JDBC Drivers work (they only need to be triggered once to be automatically registered). To avoid a strong direct coupling of your class with the driver, choose to do

%pre%

Usually on an application server, this code snippet is not required.

    
___
09.08.2014 / 06:05
1

An additional to your own answer (This should be a comment, but strangely in some questions I am unable to comment (I am a new user)).

You make DriverManager.registerDriver (Driver driver) redundant. What was happening is that your application's DriverManager was not being notified to register the driver. See the static startup section of the com.mysql.jdbc.Driver class:

    //
    // Register ourselves with the DriverManager
    //
    static {
        try {
            java.sql.DriverManager.registerDriver(new Driver());
        } catch (SQLException E) {
            throw new RuntimeException("Can't register driver!");
        }
    }

Not that this is important, but it's the way JDBC Drivers work (they only need to be triggered once to be automatically registered). To avoid a strong direct coupling of your class with the driver, choose to do

Class.forName("com.mysql.jdbc.Driver");

Usually on an application server, this code snippet is not required.

    
05.09.2014 / 04:33