jsf 2 - How to configure Spring framework to work with JSF -
i facing issue while integrating 2 different projects using maven.
springhibernateannotationexample
project services , dao related stuffs.- test web based project jsf , primefaces related jar.
now issue while integrating springhibernateannotationexample
test (web) getting problema elaborate.
springhibernateannotationexample
has beanlocation.xml having spring configuration.- test having separate applicationcontext file.
now configuring beanlocation in web.xml, when run application having jsf page getting exception unable understand:
sep 30, 2015 6:53:06 pm com.sun.faces.application.view.faceletviewhandlingstrategy handlerenderexception severe: error rendering view[/index.xhtml] com.sun.faces.mgbean.managedbeancreationexception: cant instantiate class: com.java.view.helloworld. @ com.sun.faces.mgbean.beanbuilder.newbeaninstance(beanbuilder.java:191) @ com.sun.faces.mgbean.beanbuilder.build(beanbuilder.java:100) @ 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:257) @ com.sun.faces.el.managedbeanelresolver.getvalue(managedbeanelresolver.java:117) @ 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:71) @ org.apache.el.parser.astvalue.getvalue(astvalue.java:160) @ org.apache.el.valueexpressionimpl.getvalue(valueexpressionimpl.java:184) @ 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.uioutput.getvalue(uioutput.java:174) @ com.sun.faces.renderkit.html_basic.htmlbasicinputrenderer.getvalue(htmlbasicinputrenderer.java:205) @ com.sun.faces.renderkit.html_basic.htmlbasicrenderer.getcurrentvalue(htmlbasicrenderer.java:355) @ com.sun.faces.renderkit.html_basic.labelrenderer.encodebegin(labelrenderer.java:120) @ javax.faces.component.uicomponentbase.encodebegin(uicomponentbase.java:864) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1894) @ javax.faces.render.renderer.encodechildren(renderer.java:176) @ javax.faces.component.uicomponentbase.encodechildren(uicomponentbase.java:889) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1896) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1899) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1899) @ com.sun.faces.application.view.faceletviewhandlingstrategy.renderview(faceletviewhandlingstrategy.java:451) @ com.sun.faces.application.view.multiviewhandler.renderview(multiviewhandler.java:131) @ com.sun.faces.lifecycle.renderresponsephase.execute(renderresponsephase.java:120) @ com.sun.faces.lifecycle.phase.dophase(phase.java:101) @ com.sun.faces.lifecycle.lifecycleimpl.render(lifecycleimpl.java:219) @ javax.faces.webapp.facesservlet.service(facesservlet.java:647) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:956) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:423) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1079) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:625) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:316) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(unknown source) caused by: java.lang.nullpointerexception @ com.java.view.helloworld.<init>(helloworld.java:41) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ java.lang.class.newinstance(unknown source) @ com.sun.faces.mgbean.beanbuilder.newbeaninstance(beanbuilder.java:186) ... 49 more sep 30, 2015 6:53:07 pm com.sun.faces.context.exceptionhandlerimpl log 1100: jsf1073: com.sun.faces.mgbean.managedbeancreationexception caught during processing of render_response 6 : uicomponent-clientid=, message=cant instantiate class: com.java.view.helloworld. sep 30, 2015 6:53:07 pm com.sun.faces.context.exceptionhandlerimpl log 1100: cant instantiate class: com.java.view.helloworld. com.sun.faces.mgbean.managedbeancreationexception: cant instantiate class: com.java.view.helloworld. @ com.sun.faces.mgbean.beanbuilder.newbeaninstance(beanbuilder.java:191) @ com.sun.faces.mgbean.beanbuilder.build(beanbuilder.java:100) @ 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:257) @ com.sun.faces.el.managedbeanelresolver.getvalue(managedbeanelresolver.java:117) @ 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:71) @ org.apache.el.parser.astvalue.getvalue(astvalue.java:160) @ org.apache.el.valueexpressionimpl.getvalue(valueexpressionimpl.java:184) @ 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.uioutput.getvalue(uioutput.java:174) @ com.sun.faces.renderkit.html_basic.htmlbasicinputrenderer.getvalue(htmlbasicinputrenderer.java:205) @ com.sun.faces.renderkit.html_basic.htmlbasicrenderer.getcurrentvalue(htmlbasicrenderer.java:355) @ com.sun.faces.renderkit.html_basic.labelrenderer.encodebegin(labelrenderer.java:120) @ javax.faces.component.uicomponentbase.encodebegin(uicomponentbase.java:864) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1894) @ javax.faces.render.renderer.encodechildren(renderer.java:176) @ javax.faces.component.uicomponentbase.encodechildren(uicomponentbase.java:889) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1896) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1899) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1899) @ com.sun.faces.application.view.faceletviewhandlingstrategy.renderview(faceletviewhandlingstrategy.java:451) @ com.sun.faces.application.view.multiviewhandler.renderview(multiviewhandler.java:131) @ com.sun.faces.lifecycle.renderresponsephase.execute(renderresponsephase.java:120) @ com.sun.faces.lifecycle.phase.dophase(phase.java:101) @ com.sun.faces.lifecycle.lifecycleimpl.render(lifecycleimpl.java:219) @ javax.faces.webapp.facesservlet.service(facesservlet.java:647) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:956) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:423) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1079) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:625) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:316) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(unknown source) caused by: java.lang.nullpointerexception @ com.java.view.helloworld.<init>(helloworld.java:41) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ java.lang.class.newinstance(unknown source) @ com.sun.faces.mgbean.beanbuilder.newbeaninstance(beanbuilder.java:186) ... 49 more
here files:
web.xml:
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="webapp_id" version="2.5" metadata-complete="true"> <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> <servlet-mapping> <servlet-name>faces servlet</servlet-name> <url-pattern>*.jsf</url-pattern> <!-- extension of file used localhost:..../helloworld.jsf --> </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>javax.faces.default_suffix</param-name> <param-value>.xhtml</param-value> </context-param> <context-param> <param-name>javax.faces.application.config_files</param-name> <param-value>/web-inf/faces-config.xml</param-value> </context-param> <context-param> <param-name>primefaces.theme</param-name> <param-value>glass-x</param-value> </context-param> <!-- adding spring application context loading --> <context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/applicationcontext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.contextloaderlistener </listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.requestcontextlistener </listener-class> </listener> </web-app>
faces-config:
<?xml version="1.0" encoding="utf-8"?> <faces-config 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-facesconfig_2_2.xsd" version="2.2"> <application> <el-resolver> org.springframework.web.jsf.el.springbeanfaceselresolver </el-resolver> </application> </faces-config>
applicationcontext:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:c="http://www.springframework.org/schema/c" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> <context:component-scan base-package="com.java.view" /> <import resource="classpath*:/beanlocations.xml"/> </beans>
test.pom:
<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.mytutorial</groupid> <artifactid>webprrimefaces</artifactid> <version>0.0.1-snapshot</version> <packaging>war</packaging> <name>simpleweb maven webapp</name> <description>simple web test</description> <repositories> <repository> <id>prime-repo</id> <name>primefaces maven repository</name> <url>http://repository.primefaces.org</url> <layout>default</layout> </repository> </repositories> <dependencies> <!-- adding dependency project --> <dependency> <groupid>com.mkyong.common</groupid> <artifactid>springexample</artifactid> <version>1.0-snapshot</version> <type>jar</type> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- servlet --> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>2.5</version> <scope>provided</scope> </dependency> <!-- faces implementation --> <dependency> <groupid>com.sun.faces</groupid> <artifactid>jsf-impl</artifactid> <version>2.2.4</version> </dependency> <!-- faces library --> <dependency> <groupid>com.sun.faces</groupid> <artifactid>jsf-api</artifactid> <version>2.2.4</version> </dependency> <!-- primefaces version 5 --> <dependency> <groupid>org.primefaces</groupid> <artifactid>primefaces</artifactid> <version>5.0</version> </dependency> <!-- jsp library --> <dependency> <groupid>javax.servlet.jsp</groupid> <artifactid>javax.servlet.jsp-api</artifactid> <version>2.3.1</version> </dependency> <!-- jstl library --> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <version>1.1.2</version> </dependency> <!-- primefaces theme library --> <dependency> <groupid>org.primefaces.themes</groupid> <artifactid>glass-x</artifactid> <version>1.0.6</version> </dependency> <!-- spring web dependency --> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-web</artifactid> <version>4.1.4.release</version> </dependency> </dependencies> <build> <sourcedirectory>src</sourcedirectory> <plugins> <plugin> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <artifactid>maven-war-plugin</artifactid> <version>2.3</version> <configuration> <warsourcedirectory>webcontent</warsourcedirectory> <failonmissingwebxml>false</failonmissingwebxml> </configuration> </plugin> </plugins> </build> </project>
helloworld:
package com.java.view; import java.io.serializable; import javax.faces.bean.managedbean; import javax.faces.bean.sessionscoped; import org.springframework.beans.factory.annotation.autowired; import com.mkyong.stock.bo.stockbo; import com.mkyong.stock.model.stock; @managedbean(name = "helloworld") @sessionscoped public class helloworld implements serializable { private static final long serialversionuid = -6913972022251814607l; //private string s1 = "hello world!!"; @autowired private stockbo stockbo; public stockbo getstockbo() { return stockbo; } public void setstockbo(stockbo stockbo) { this.stockbo = stockbo; } stock stck=stockbo.findbystockcode("7668"); }
index.xhtml
<?xml version='1.0' encoding='utf-8' ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>hello world jsf example</title> </h:head> <h:body> <h1>hello world primefaces</h1> <f:view> <h:form> <h:outputlabel value="#{stck.stockname}" /> </h:form> </f:view> </h:body> </html>
i know not example sole intention inject dependency of spring related beans jsf/web application, have applicationcontext in web project (test) , other applicationcontext (beanlocation.xml) in different project.
Comments
Post a Comment