<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-112  評(píng)論-73  文章-0  trackbacks-0

    JSF2.0 與Spring 3.0 集成

    同以前的JSF1.2Spring2.5集成類似,只是有一些類名的變化。

    web.xml 代碼如下:

    <context-param>
            
    <param-name>contextConfigLocation</param-name>
            
    <param-value>WEB-INF/applicationContext.xml</param-value>
        
    </context-param>
        
    <listener>
            
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
        
    </listener>
        
    <listener>
            
    <listener-class> org.springframework.web.context.ContextLoaderListener
                
    </listener-class>
        
    </listener>
        
    <listener>
            
    <listener-class>
                org.springframework.web.context.request.RequestContextListener
    </listener-class>
        
    </listener>
        
    <servlet>
            
    <servlet-name>Faces Servlet</servlet-name>
            
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            
    <load-on-startup>1</load-on-startup>
        
    </servlet>
        
    <servlet-mapping>
            
    <servlet-name>Faces Servlet</servlet-name>
            
    <url-pattern>*.xhtml</url-pattern>
        
    </servlet-mapping>
        
    <servlet-mapping>
            
    <servlet-name>Faces Servlet</servlet-name>
            
    <url-pattern>*.jsf</url-pattern>
        
    </servlet-mapping>
        
    <context-param>
            
    <param-name>javax.faces.PROJECT_STAGE</param-name>
            
    <param-value>Development</param-value>
        
    </context-param>
        
    <welcome-file-list>
            
    <welcome-file>index.html</welcome-file>
        
    </welcome-file-list>


    Faces-config.xml中加入:

    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>

    JSF1.21.2以前是加入

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

    Spring 的配置文件就正常配置就可以了。

    ApplicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <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"
        xsi:schemaLocation
    ="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
    >
        
    <!--
            <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="location" value="WEB-INF/jdbc.properties" /> </bean>
        
    -->
        
    <!-- hibernate sessionFactory -->
        
    <context:annotation-config/>
        
    <context:component-scan base-package="cn.xiangyunsoft" />
        
    <bean id="sessionFactory"
            class
    ="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            
    <property name="hibernateProperties" value="classpath:hibernate.properties" />
            
    <property name="configLocations">
                
    <list>
                    
    <!-- 使用hibernate.cfg.xml配置文件 -->
                    
    <value>classpath:hibernate.cfg.xml
                    
    </value>
                
    </list>
            
    </property>
        
    </bean>
        
    <!-- 配置事務(wù)管理 -->
        
    <!-- 事務(wù)通知類 -->
        
    <!--
            <bean id="profiler"
            class="cn.xiangyunsoft.business.service.SimpleProfiler"> order
            值可以決定通知的先后順序 ,與后面的order的值的大小,決定了是先通知再執(zhí)行,還是先執(zhí)行再通知 <property
            name="order" value="2" /> </bean>
        
    -->
        
    <bean id="transactionManager"
            class
    ="org.springframework.orm.hibernate3.HibernateTransactionManager">
            
    <property name="sessionFactory" ref="sessionFactory" />
        
    </bean>
        
    <aop:config>
            
    <!-- 此處的IService 是表示對(duì)所有實(shí)現(xiàn)IService接口的類管理事務(wù) -->
            
    <aop:advisor
                
    pointcut="execution(* cn.xiangyunsoft.*.service..*ServiceImpl.*(..))"
                advice-ref
    ="txAdvice" />
            
    <!--
                加入之后事務(wù)不起作用> <aop:aspect id="profilingAspect" ref="profiler">
                <aop:pointcut id="serviceMethodWithReturnValue"
                expression="execution(*
                cn.xiangyunsoft.*.service..*ServiceImpl.*(..))" />
                <aop:after-throwing method="profile"
                pointcut-ref="serviceMethodWithReturnValue" /> </aop:aspect
            
    -->
        
    </aop:config>
        
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
            
    <!-- the transactional semantics -->
            
    <tx:attributes>
                
    <!-- 以get、find、load開(kāi)頭的方法是只讀事務(wù) -->
                
    <tx:method name="*" read-only="true" />
                
    <!--<tx:method name="find*" read-only="true" />-->
                
    <!--<tx:method name="load*" read-only="true" />-->
                
    <!-- 其他方法是默認(rèn),事務(wù)隔離級(jí)別為:保證一個(gè)事務(wù)修改的數(shù)據(jù)提交后才能被另外一個(gè)事務(wù)讀取 -->
                
    <tx:method name="save*" isolation="REPEATABLE_READ"
                    propagation
    ="REQUIRED" />
                
    <tx:method name="delete*" isolation="REPEATABLE_READ"
                    propagation
    ="REQUIRED" />
                    
            
    </tx:attributes>
        
    </tx:advice>
    </beans>


    一個(gè)注入Spring bean 的 JSF bean 代碼如下:

    @ManagedBean(name = ClassItemBean.NAME)
    public class ClassItemBean {

        
    public static final String NAME = "classItemBean";

        
    /*
         *在spring 中配置的service.
         
    */
        @ManagedProperty(name 
    = "classItemService", value = "#{classItemService}")
        
    private ClassItemService classItemService;

        
    public void setClassItemService(ClassItemService classItemService) {
            
    this.classItemService = classItemService;
        }

        
    public String hello() {
            System.out.println(
    "hello." + classItemService);
            Object obj 
    = classItemService.get(ClassItem.class"01");
            System.out.println(
    "obj = " + obj);
            
    return null;
        }
    }


    這樣集成就完畢了。很簡(jiǎn)單,很強(qiáng)大。




    posted on 2010-04-24 15:03 Libo 閱讀(2870) 評(píng)論(2)  編輯  收藏 所屬分類: SpringJSF 2

    評(píng)論:
    # re: JSF2.0 與Spring 3.0 集成 2010-07-19 17:53 | 任亮
    請(qǐng)問(wèn),博主用的什么服務(wù)器。怎么配置的啊。我現(xiàn)在在做一個(gè)jsf2.0的項(xiàng)目,想用jboss4.2服務(wù)器,但是配置不對(duì),希望博主幫忙。  回復(fù)  更多評(píng)論
      
    # re: JSF2.0 與Spring 3.0 集成 2010-07-26 17:24 | Libo
    @任亮
    我使用的是glassfish,tomcat6 也可以。jboss4.2沒(méi)用過(guò)。  回復(fù)  更多評(píng)論
      
    主站蜘蛛池模板: 亚洲第一区二区快射影院| 国产AV无码专区亚洲AWWW| 91在线亚洲精品专区| 野花香在线视频免费观看大全| 中文字幕第13亚洲另类| 美女尿口扒开图片免费| 免费人成视频x8x8入口| 国产成人精品亚洲| 亚洲av无码专区在线观看素人| 特级aaaaaaaaa毛片免费视频| 午夜亚洲福利在线老司机| aaa毛片免费观看| 亚洲AV无码码潮喷在线观看| 国产精品视频白浆免费视频| 亚洲视频一区在线播放| 日韩免费一区二区三区在线播放| 亚洲av专区无码观看精品天堂| 免费高清在线影片一区| 一级特黄色毛片免费看| 亚洲AV午夜福利精品一区二区| 久久久久国产精品免费网站| 亚洲偷自精品三十六区| 思思99re66在线精品免费观看| 亚洲精品理论电影在线观看| 亚洲中文字幕成人在线| 久久精品国产这里是免费| 亚洲AV综合色区无码二区爱AV| 亚洲 自拍 另类小说综合图区| 男人天堂免费视频| 亚洲日产2021三区在线| 免费看片免费播放| 国内精品免费久久影院| 亚洲国产成人在线视频| 亚洲精品国产精品国自产观看| 男女午夜24式免费视频| 亚洲一区二区三区高清不卡| 亚洲七七久久精品中文国产| 久久不见久久见免费视频7| 亚洲av无码一区二区三区天堂| 久久久久亚洲AV综合波多野结衣| 老汉精品免费AV在线播放|