2014-11-24 168 views
0

我使用的是春天的罐子:JSF 2.0的Spring bean注入

spring-web-2.5.5.jar 
spring-context-2.5.5.jar 
spring-core-2.5.5.jar 
spring-orm-2.5.5.jar 
spring-support-2.0.8.jar 
spring-security-taglibs-2.0.3.jar 
spring-security-acl-2.0.3.jar 
spring-security-core-2.0.4.jar 
spring-aop-2.5.5.jar 
spring-jdbc-2.5.5.jar 
spring-tx-2.5.5.jar 

問題是從JSF 1.2JSF 2.0豆,在faces-context中定義的遷移後不能被注入到與會話管理bean範圍。例如:

<managed-bean> 
    <managed-bean-name>bannersController</managed-bean-name> 
    <managed-bean-class>jaxp.com.controller.BannersController</managed-bean-class> 
     <managed-bean-scope>request</managed-bean-scope> 
     <managed-property> 
      <property-name>bannerDao</property-name> 
      <value>#{bannerDao}</value> 
     </managed-property> 
</managed-bean> 

<bean id="bannerDao" class="jaxp.com.db.dao.BannerDaoImpl" 
    scope="prototype"> 
    <property name="sessionFactory" ref="sitePartnerSessionFactory" /> 
    <property name="dataSource" ref="sitePartnerDataSource" /> 
</bean> 

當我更換豆到會議的範圍,它會正常工作。但是現在,託管屬性是空的。它在我們遷移到JSF 2.0之前就已經工作了。怎麼了,怎麼解決?

UPD:如果我設置託管bean的作用域查看範圍也工作正常/

+0

停止混合使用不同版本的春春... 2.5.5和2.0。 8不要混合。也不知道爲什麼你的道是原型範圍,應該是單身imho。請確保您已經配置了正確的解析爲JSF只會用正確的集成安裝工作... – 2014-11-25 09:43:54

+0

看到我的完整的答案在標籤完整的答案: [的Spring bean注入到JSF豆] [1] [1]:http://stackoverflow.com/questions/27094466/injection-service-spring-on-managedbean-failed-npe/27113201#27113201 – 2014-11-25 11:43:11

回答

1

JSF豆:

inject spring service 
@ManagedProperty("#{handlerService}") 
private HandlerService handlerService = null; 
///add setter 
Spring service: 

@Service("handlerService") 
@Component 
public class HandlerService { 
    @Autowired 
    private DomainService domainService; 

faces-config.xml 
    <application>  
     <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>     
    </application> 
------------ 
web.xml 

<context-param> 
     <param-name>contextClass</param-name> 
     <param-value> 
      org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
     </param-value> 
    </context-param> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>com.myspringconfgigclass.CommonCoreConfig</param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener>