简体   繁体   English

JSF 2.0 Spring bean注入

[英]JSF 2.0 Spring bean injection

I'm using the following spring's jars: 我正在使用以下弹簧罐:

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

The issue is after migration from JSF 1.2 to JSF 2.0 beans, defined in the faces-context cannot be injected into a managed bean with session scope. 问题是在从faces-context中定义的从JSF 1.2迁移到JSF 2.0 Bean之后,无法将其注入具有会话范围的托管Bean中。 For instance: 例如:

<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>

and

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

When I replace the scope of the bean to session it'll work fine. 当我替换bean的作用域进行会话时,它将正常工作。 But now, the managed property is just null. 但是现在,托管属性只是null。 It had worked before we migrated to JSF 2.0. 在我们迁移到JSF 2.0之前,它已经奏效。 What's wrong and how to fix? 怎么了,怎么解决?

UPD: If I set managed bean scope to view scope it also works fine/ UPD:如果我将托管bean范围设置为查看范围,那么它也可以正常工作/

JSF bean: JSF bean:

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>  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM