2014-11-24 116 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>