Error Initialize ManagedBean with Spring JSF 2.0 Hibernate Maven -


i working jsf 2.0 , spring, hibernate , i'm having problem initialization of managedbean.

here error:

severe: error rendering view[/cadastrodeprodutoadminsistemas.xhtml]  com.sun.faces.mgbean.managedbeancreationexception: não é possível criar instância     para·a classe: com.catalogor3e.controller.pesquisasistemasadminbean. @ com.sun.faces.mgbean.beanbuilder.newbeaninstance(beanbuilder.java:193) @ com.sun.faces.mgbean.beanbuilder.build(beanbuilder.java:102) @ com.sun.faces.mgbean.beanmanager.createandpush(beanmanager.java:409) @ com.sun.faces.mgbean.beanmanager.create(beanmanager.java:269) @ com.sun.faces.el.managedbeanelresolver.resolvebean(managedbeanelresolver.java:244) @ com.sun.faces.el.managedbeanelresolver.getvalue(managedbeanelresolver.java:116) @ com.sun.faces.el.demuxcompositeelresolver._getvalue(demuxcompositeelresolver.java:176) @ com.sun.faces.el.demuxcompositeelresolver.getvalue(demuxcompositeelresolver.java:203) @ org.apache.el.parser.astidentifier.getvalue(astidentifier.java:72) @ org.apache.el.parser.astvalue.getvalue(astvalue.java:161) @ org.apache.el.valueexpressionimpl.getvalue(valueexpressionimpl.java:185) @ com.sun.faces.facelets.el.tagvalueexpression.getvalue(tagvalueexpression.java:109) @ javax.faces.component.componentstatehelper.eval(componentstatehelper.java:194) @ javax.faces.component.componentstatehelper.eval(componentstatehelper.java:182) @ javax.faces.component.uidata.getvalue(uidata.java:731) @ org.primefaces.component.datatable.datatable.getvalue(datatable.java:729) @ org.primefaces.component.api.uidata.getdatamodel(uidata.java:575) @ javax.faces.component.uidata.getrowcount(uidata.java:356) @ org.primefaces.component.datatable.datatablerenderer.encodetbody(datatablerenderer.java:579) @ org.primefaces.component.datatable.datatablerenderer.encoderegulartable(datatablerenderer.java:220) @   org.primefaces.component.datatable.datatablerenderer.encodemarkup(datatablerenderer.java:192) @   org.primefaces.component.datatable.datatablerenderer.encodeend(datatablerenderer.java:74) @ javax.faces.component.uicomponentbase.encodeend(uicomponentbase.java:875) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1764) @ javax.faces.render.renderer.encodechildren(renderer.java:168) @ javax.faces.component.uicomponentbase.encodechildren(uicomponentbase.java:845) @ org.primefaces.renderkit.corerenderer.renderchild(corerenderer.java:55) @ org.primefaces.renderkit.corerenderer.renderchildren(corerenderer.java:43) @ org.primefaces.component.layout.layoutunitrenderer.encodeend(layoutunitrenderer.java:51) @ javax.faces.component.uicomponentbase.encodeend(uicomponentbase.java:875) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1764) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1760) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1760) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1760) @   com.sun.faces.application.view.faceletviewhandlingstrategy.renderview(faceletviewhandlingstrategy.java:424) @ com.sun.faces.application.view.multiviewhandler.renderview(multiviewhandler.java:125) @ com.sun.faces.lifecycle.renderresponsephase.execute(renderresponsephase.java:121) @ com.sun.faces.lifecycle.phase.dophase(phase.java:101) @ com.sun.faces.lifecycle.lifecycleimpl.render(lifecycleimpl.java:139) @ javax.faces.webapp.facesservlet.service(facesservlet.java:594) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:305)     hibernate: select estado0_.id id3_, estado0_.nome_estado nome2_3_ estado    estado0_ @   org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.primefaces.webapp.filter.fileuploadfilter.dofilter(fileuploadfilter.java:79) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:243) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:222) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:123) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:472) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:171) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:99) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:936) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:407) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1004) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:589) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:312) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1110) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:603) @ java.lang.thread.run(thread.java:722)        caused by: java.lang.nullpointerexception @ com.catalogor3e.controller.pesquisasistemasadminbean.<init>(pesquisasistemasadminbean.java:51)  @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method)  @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:57) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:525) @ java.lang.class.newinstance0(class.java:372) @ java.lang.class.newinstance(class.java:325) @ com.sun.faces.mgbean.beanbuilder.newbeaninstance(beanbuilder.java:188) ... 58 more 

here managedbean:

@managedbean(name="pesquisasistemasadminbean") @sessionscoped public class pesquisasistemasadminbean{  @managedproperty(value = "#{filtroetiquetacidadesistemabean}")     private filtroetiquetacidadesistemabean filtroetiquetacidadesistemabean;  @managedproperty("#{facadeservice}") private facadeservice service;  private datamodel<sistema> listasistemas ;  //variáveis para filtro private int idcategoriaparafiltro = -1; private list<string> idsdecomponentesparafiltro = new arraylist<string>(); private int idfabricanteparafiltro = -1;   public pesquisasistemasadminbean() {     this.listasistemas = new listdatamodel<sistema>  (this.service.getservicesistemas().filtrarsistemaconstrutivo(null, null, null, null, null)); }   //retorna todas categorias(tipos) dos sistemas existentes no banco public list<categoriasistema> getlistadecategorias(){     list<categoriasistema> listadecategorias = this.service.getservicecategoriadesistemas().gettodasascategoriasdesistemas();     return listadecategorias; }  public void filtrarsistemaconstrutivo(){      categoriasistema categoriadesistema = null;      fabricante fabricante = null;      zonabioclimatica zona = null;      etiqueta etiqueta = null;      list<categoriacamada> listadecategoriasdecomponentes = null;      if(this.idcategoriaparafiltro != -1){          categoriadesistema =  this.service.getservicecategoriadesistemas().getcategoriapeloid(idcategoriaparafiltro);      }      if(this.idfabricanteparafiltro != -1){          fabricante = this.service.getservicefabricante().getfabricantepeloid(idcategoriaparafiltro);      }      if(this.filtroetiquetacidadesistemabean.getzonabioclimaticaparafiltro() != null){          zona = this.filtroetiquetacidadesistemabean.getzonabioclimaticaparafiltro();      }      if(this.filtroetiquetacidadesistemabean.getidetiqueta() != -1){          etiqueta = this.service.getservicecidadeestado().getetiquetapeloid(this.filtroetiquetacidadesistemabean.getidetiqueta());      }       if(!this.idsdecomponentesparafiltro.isempty()){          listadecategoriasdecomponentes = new arraylist<categoriacamada>();          for(int = 0; < idsdecomponentesparafiltro.size(); i++){              categoriacamada categoriacamada = this.service.getservicecategoriadecomponentesconstrutivos().getcategoriacomponenteconstrutivopeloid(integer.parseint(idsdecomponentesparafiltro.get(i)));              listadecategoriasdecomponentes.add(categoriacamada);          }      }      this.listasistemas = new listdatamodel<sistema>  (this.service.getservicesistemas().filtrarsistemaconstrutivo(categoriadesistema, listadecategoriasdecomponentes, fabricante, zona, etiqueta)); }  //retorna todos os fabricantes existentes no banco  public list<fabricante> getlistafabricantes(){     list<fabricante> listadefabricantes = this.service.getservicefabricante().listadetodososfabricantes();     return listadefabricantes; }   ///gets e sets está implementado, mas economizei código aqui!!! 

here pom.xml

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"      xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion>  <groupid>com.mycompany</groupid> <artifactid>catalogo</artifactid> <version>1.0-snapshot</version> <packaging>war</packaging>  <name>catalogo</name>  <properties>     <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>     <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties>  <dependencies>     <dependency> <groupid>com.sun.faces</groupid> <artifactid>jsf-api</artifactid> <version>2.1.6</version> </dependency>    <dependency>    <groupid>com.sun.faces</groupid>    <artifactid>jsf-impl</artifactid>    <version>2.1.10</version>   </dependency>   <dependency>    <groupid>javax.servlet</groupid>    <artifactid>jstl</artifactid>    <version>1.2</version> </dependency>  <dependency>   <groupid>javax.persistence</groupid>   <artifactid>persistence-api</artifactid>    <version>1.0</version>  </dependency>   <dependency>         <groupid>org.springframework</groupid>         <artifactid>spring-test</artifactid>         <version>3.2.2.release</version>     </dependency>  <dependency>    <groupid>org.springframework</groupid>    <artifactid>spring-core</artifactid>    <version>3.1.2.release</version>  </dependency>  <dependency>   <groupid>org.springframework</groupid>   <artifactid>spring-expression</artifactid>   <version>3.1.2.release</version> </dependency>  <dependency>   <groupid>org.springframework</groupid>   <artifactid>spring-beans</artifactid>   <version>3.1.2.release</version> </dependency>  <dependency>   <groupid>org.springframework</groupid>   <artifactid>spring-aop</artifactid>   <version>3.1.2.release</version> </dependency>  <dependency>   <groupid>org.springframework</groupid>   <artifactid>spring-context</artifactid>   <version>3.1.2.release</version> </dependency>  <dependency>   <groupid>org.springframework</groupid>   <artifactid>spring-context-support</artifactid>   <version>3.1.2.release</version> </dependency>  <dependency>   <groupid>org.springframework</groupid>   <artifactid>spring-tx</artifactid>   <version>3.1.2.release</version> </dependency>  <dependency>   <groupid>org.springframework</groupid>   <artifactid>spring-jdbc</artifactid>   <version>3.1.2.release</version> </dependency>  <dependency>   <groupid>org.springframework</groupid>    <artifactid>spring-orm</artifactid>   <version>3.1.2.release</version> </dependency>    <dependency>   <groupid>org.springframework</groupid>   <artifactid>spring-web</artifactid>   <version>3.1.2.release</version> </dependency>  <dependency>             <groupid>org.hibernate</groupid>             <artifactid>hibernate</artifactid>             <version>3.2.6.ga</version>             <type>jar</type>         </dependency>         <dependency>             <groupid>org.hibernate</groupid>             <artifactid>hibernate-annotations</artifactid>             <version>3.3.1.ga</version>             <type>jar</type>         </dependency>         <dependency>             <groupid>org.hibernate</groupid>             <artifactid>hibernate-entitymanager</artifactid>             <version>3.3.2.ga</version>             <type>jar</type>         </dependency>  <dependency>   <groupid>mysql</groupid>   <artifactid>mysql-connector-java</artifactid>   <version>5.1.15</version> </dependency>   <dependency>   <groupid>org.slf4j</groupid>   <artifactid>slf4j-api</artifactid>    <version>1.6.1</version> </dependency>  <dependency>   <groupid>org.slf4j</groupid>   <artifactid>slf4j-simple</artifactid>   <version>1.6.1</version> </dependency>  <dependency>    <groupid>commons-collections</groupid>   <artifactid>commons-collections</artifactid>   <version>3.1</version>  </dependency>   <dependency>   <groupid>junit</groupid>   <artifactid>junit</artifactid>   <version>4.10</version>   <scope>test</scope> </dependency>   <dependency>    <groupid>org.hibernate</groupid>    <artifactid>ejb3-persistence</artifactid>    <version>1.0.1.ga</version> </dependency>  <dependency>   <groupid>javax.sql</groupid>   <artifactid>jdbc-stdext</artifactid>   <version>2.0</version> </dependency>  <dependency>   <groupid>javax.transaction</groupid>   <artifactid>jta</artifactid>   <version>1.0.1b</version> </dependency>  <dependency>   <groupid>org.primefaces</groupid>     <artifactid>primefaces</artifactid>   <version>3.4.1</version> </dependency>  <dependency>   <groupid>org.primefaces.themes</groupid>   <artifactid>all-themes</artifactid>   <version>1.0.9</version> </dependency>  <dependency> <groupid>commons-fileupload</groupid> <artifactid>commons-fileupload</artifactid> <version>1.2.3-snapshot</version> </dependency> <dependency> <groupid>commons-io</groupid> <artifactid>commons-io</artifactid> <version>2.5-snapshot</version> </dependency> <dependency> <groupid>rome</groupid> <artifactid>rome</artifactid> <version>1.0</version> </dependency> <dependency> <groupid>org.apache.poi</groupid> <artifactid>poi</artifactid> <version>3.7</version> </dependency>    <dependency> <groupid>com.lowagie</groupid> <artifactid>itext</artifactid> <version>2.0.7</version> </dependency>     <dependency>         <groupid>javax</groupid>         <artifactid>javaee-api</artifactid>         <version>6.0</version>         <type>jar</type>     </dependency>     <dependency>         <groupid>javax</groupid>         <artifactid>javaee-web-api</artifactid>         <version>6.0</version>         <type>jar</type>     </dependency> </dependencies>  <build>     <plugins>         <plugin>             <groupid>org.apache.maven.plugins</groupid>             <artifactid>maven-compiler-plugin</artifactid>             <version>2.3.2</version>             <configuration>                 <source>1.6</source>                 <target>1.6</target>                 <compilerarguments>                     <endorseddirs>${endorsed.dir}</endorseddirs>                 </compilerarguments>             </configuration>         </plugin>         <plugin>             <groupid>org.apache.maven.plugins</groupid>             <artifactid>maven-war-plugin</artifactid>             <version>2.1.1</version>             <configuration>                 <failonmissingwebxml>false</failonmissingwebxml>             </configuration>         </plugin>         <plugin>             <groupid>org.apache.maven.plugins</groupid>             <artifactid>maven-dependency-plugin</artifactid>             <version>2.1</version>             <executions>                 <execution>                     <phase>validate</phase>                     <goals>                         <goal>copy</goal>                     </goals>                     <configuration>                         <outputdirectory>${endorsed.dir}</outputdirectory>                         <silent>true</silent>                         <artifactitems>                             <artifactitem>                                 <groupid>javax</groupid>                                 <artifactid>javaee-endorsed-api</artifactid>                                 <version>6.0</version>                                 <type>jar</type>                             </artifactitem>                         </artifactitems>                     </configuration>                 </execution>             </executions>         </plugin>     </plugins> </build> <repositories>     <repository>         <url>http://download.java.net/maven/2/</url>         <id>jsf20</id>         <layout>default</layout>         <name>repository library library[jsf20]</name>     </repository>     <repository>         <url>http://repo1.maven.org/maven2/</url>         <id>jstl11</id>         <layout>default</layout>         <name>repository library library[jstl11]</name>     </repository>     <repository>           <id>prime-repo</id>           <name>primefaces maven repository</name>           <url>http://repository.primefaces.org</url>           <layout>default</layout>       </repository>            <repository>             <releases>             <enabled>false</enabled>         </releases>         <snapshots>             <enabled>true</enabled>         </snapshots>         <id>apache.snapshots</id>         <name>apache snapshot repository</name>         <url>https://repository.apache.org/content/repositories/snapshots</url>     </repository> </repositories> 

here web.xml

<?xml version="1.0" encoding="utf-8"?> <web-app version="3.0"       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-app_3_0.xsd">   <context-param>     <param-name>javax.faces.project_stage</param-name>     <param-value>development</param-value> </context-param>   <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>/faces/*</url-pattern> </servlet-mapping> <session-config>     <session-timeout>         30     </session-timeout> </session-config>  <welcome-file-list>     <welcome-file>faces/index.xhtml</welcome-file> </welcome-file-list>  <context-param>     <param-name>primefaces.theme</param-name>     <param-value>bootstrap</param-value> </context-param>     <filter-mapping>     <filter-name>primefaces fileupload filter</filter-name>      <servlet-name>faces servlet</servlet-name>     </filter-mapping>    <filter>     <filter-name>primefaces fileupload filter</filter-name>          <filter-class>org.primefaces.webapp.filter.fileuploadfilter</filter-class>     </filter>          <context-param>     <param-name>contextconfiglocation</param-name>     <param-value>/web-inf/applicationcontext.xml</param-value>   </context-param>  <listener>   <listener-class>      org.springframework.web.context.request.requestcontextlistener   </listener-class>  </listener>  <listener>   <listener-class>      org.springframework.web.context.contextloaderlistener   </listener-class>  </listener>  </web-app> 

here applicationcontext.xml

  <?xml version="1.0" encoding="utf-8"?>  <beans xmlns="http://www.springframework.org/schema/beans"   xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"    xmlns:context="http://www.springframework.org/schema/context"   xmlns:tx="http://www.springframework.org/schema/tx"    xsi:schemalocation="http://www.springframework.org/schema/beans      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-3.0.xsd     http://www.springframework.org/schema/tx     http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">    <!-- seta anotaçoes para serem  <context:annotation-config />usadas pelo spring -->   <context:annotation-config />     <!-- define o pacote onde o spring vai procurar por beans anotados -->    <context:component-scan base-package="com.catalogor3e.dao, com.catalogor3e.service"  />    <!-- define que transaçoes irao ser anotadas -->   <tx:annotation-driven />     <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource">     <property name="driverclassname" value="com.mysql.jdbc.driver"/>     <property name="url" value="jdbc:mysql://localhost:3306/bancodedados"/>     <property name="username" value="root"/>     <property name="password" value="852456"/>   </bean>  < bean id="entitymanagerfactory"  class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean">         <property name="persistenceunitname" value="catalogopu" />         <property name="datasource" ref="datasource" />         <property name="jpavendoradapter">             <bean class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter">                 <property name="databaseplatform" value="org.hibernate.dialect.mysqldialect" />                 <property name="showsql" value="true" />              </bean>         </property> </bean>  <!-- configuracao gerente de transacoes spring --> <bean id="transactionmanager"   class="org.springframework.orm.jpa.jpatransactionmanager">     <property name="entitymanagerfactory" ref="entitymanagerfactory" /> </bean>  </beans> 

please, can me this, please?

att,

diego sabino

here's root cause of exception, it's bottommost part. that's of relevance:

caused by: java.lang.nullpointerexception     @ com.catalogor3e.controller.pesquisasistemasadminbean.<init>(pesquisasistemasadminbean.java:51) 

so, null inside bean's constructor while code attempting access/invoke it. let's @ constructor:

public pesquisasistemasadminbean() {     this.listasistemas = new listdatamodel<sistema>  (this.service.getservicesistemas().filtrarsistemaconstrutivo(null, null, null, null, null)); } 

hey, you're trying access service declared managed property. seem expecting managed property injection works follows:

pesquisasistemasadminbean pesquisasistemasadminbean; // declare bean. pesquisasistemasadminbean.setservice(facadeservice); // set service. pesquisasistemasadminbean = new pesquisasistemasadminbean(); // invoke constructor. 

but impossible. technically not possible set service instance variable before instance ever constructed. actually, following happens:

pesquisasistemasadminbean pesquisasistemasadminbean; // declare bean. pesquisasistemasadminbean = new pesquisasistemasadminbean(); // invoke constructor. pesquisasistemasadminbean.setservice(facadeservice); // set service. 

that explains why service still null inside constructor. if intend perform business logic based on injected dependencies directly after bean's construction, should using @postconstruct annotated method.

so, need replace constructor

public pesquisasistemasadminbean() {     this.listasistemas = new listdatamodel<sistema>  (this.service.getservicesistemas().filtrarsistemaconstrutivo(null, null, null, null, null)); } 

by @postconstruct method

@postconstruct public void init() {     this.listasistemas = new listdatamodel<sistema>  (this.service.getservicesistemas().filtrarsistemaconstrutivo(null, null, null, null, null)); } 

the method name choice, way.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -