在Spring Beans中的JSF

在Spring Beans中的JSF


http://blog.rainer.eschen.name/2007/08/21/jsf-on-spring-beans/
以前,我写过在混合依赖注入环境中怎样使用backing beans。我的blog目录描述了怎样在JSF和Spring中写POJOs,以及在基于JSF的表现层使用它们。但是,Web容器的配置有时是missing的。
1)Configuration(配置)
其配置是非常简单的。我们需要一个指定的listener,叫RequestContextListener,和一个resolver,名为DelegatingVariableResolver。两者都来自Spring的配置,当backing bean识别符被映射到一个bean时,起到调派(dispatching)作用。这个配置允许把所有指定的JSF定义移动到Spring context。
管理backing beans更好的方法时把应用程序上下文(application context)文件分成多个文件。要识别上下文,需要用“spring-”给文件名加上前缀。
下面是web.xml的代码,在packages有一些beans,“security”,“commons”,“context”。

< context-param >
    
< param-name > contextConfigLocation </ param-name >
    
< param-value >
        /WEB-INF/spring-security.xml,
        /WEB-INF/spring-commons.xml,
        /WEB-INF/spring-context.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 >

 

下面是faces-config.xml文件:

< application >
    
< variable-resolver > org.springframework.web.jsf.DelegatingVariableResolver </ variable-resolver >
</ application >

 

2)Maven建立
如果使用Maven2,你必须增加一些Spring的依赖。依赖于你使用的其它框架,如Acegi,你还可以增加更多的依赖。如下:

< dependency >
    
< groupId > org.springframework </ groupId >
    
< artifactId > spring </ artifactId >
    
< version > 2.0.6 </ version >
</ dependency >

< dependency >
    
< groupId > cglib </ groupId >
    
< artifactId > cglib </ artifactId >
    
< version > 2.1_3 </ version >
</ dependency >

< dependency >
    
< groupId > asm </ groupId >
    
< artifactId > asm </ artifactId >
    
< version > 1.5.3 </ version >
</ dependency >

< dependency >
    
< groupId > asm </ groupId >
    
< artifactId > asm-attrs </ artifactId >
    
< version > 1.5.3 </ version >
</ dependency >
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值