Note that there are some explanatory texts on larger screens.

plurals
  1. POproblem with using spring beans from jsf managed bean
    primarykey
    data
    text
    <p>I have web application wich uses jsf 2.0 and spring 3.0 The problem is that: jsf managed beans can't use spring beans using dependency injection There are my config files:</p> <p>web.xml:</p> <pre><code>&lt;web-app&gt; &lt;display-name&gt;Archetype Created Web Application&lt;/display-name&gt; &lt;!-- Faces Servlet --&gt; &lt;servlet&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt; 1 &lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;!-- Faces Servlet Mapping --&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/calc/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/spring-beans.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt; org.springframework.web.context.ContextLoaderListener &lt;/listener-class&gt; &lt;/listener&gt; </code></pre> <p></p> <p>faces-config.xml:</p> <pre><code>&lt;application&gt; &lt;el-resolver&gt;org.springframework.web.jsf.el.SpringBeanFacesELResolver&lt;/el-resolver&gt; &lt;/application&gt; &lt;managed-bean&gt; &lt;managed-bean-name&gt;CalcBean&lt;/managed-bean-name&gt; &lt;managed-bean-class&gt;timur.org.bean.CalculatorConroller&lt;/managed-bean-class&gt; &lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt; &lt;managed-property&gt; &lt;property-name&gt;hibernateUtil&lt;/property-name&gt; &lt;value&gt;#{hibernateUtil}&lt;/value&gt; &lt;/managed-property&gt; &lt;/managed-bean&gt; </code></pre> <p>spring-beans.xml:</p> <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd"&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;property name="driverClassName" value="org.postgresql.Driver"/&gt; &lt;property name="url" value="jdbc:postgresql://localhost/timur"/&gt; &lt;property name="username" value="postgres"/&gt; &lt;property name="password" value="postgres"/&gt; &lt;/bean&gt; &lt;bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt; &lt;property name="dataSource" ref="dataSource"/&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource"/&gt; &lt;property name="mappingResources"&gt; &lt;list&gt; &lt;value&gt;/mapping/service.xml&lt;/value&gt; &lt;value&gt;/mapping/city.xml&lt;/value&gt; &lt;value&gt;/mapping/timurovec.xml&lt;/value&gt; &lt;value&gt;/mapping/client.xml&lt;/value&gt; &lt;value&gt;/mapping/calendar.xml&lt;/value&gt; &lt;value&gt;/mapping/order.xml&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/prop&gt; &lt;prop key="show_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="hibernateUtil" class="timur.org.util.HibernateUtil"&gt; &lt;property name="sessionFactory" ref="sessionFactory"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="txManager"&gt;&lt;/tx:annotation-driven&gt; </code></pre> <p></p> <p>CalculateController:</p> <pre><code>public class CalculatorConroller { private HibernateUtil hibernateUtil; public void setHibernateUtil(HibernateUtil hibernateUtil) { this.hibernateUtil = hibernateUtil; } public String action() { hibernateUtil.createAndStoreEvent("",new Date()); List&lt;CityDomain&gt; lc = hibernateUtil.getList(); for (int i=0; i&lt;lc.size(); i++){ LogManager.getLogger(this.getClass()).debug(lc.get(i).getName()); } return "success"; } </code></pre> <p>}</p> <p>when i run my web application and call my controller action variable 'hibernateUtil' is null and there no exceptions. But i can get spring beans using:</p> <pre><code> hibernateUtil = (HibernateUtil) FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()).getBean("hibernateUtil"); </code></pre> <p>How can i get this spring bean using dependency injection?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload