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

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

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

    隨筆-112  評論-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>
        
    <!-- 配置事務管理 -->
        
    <!-- 事務通知類 -->
        
    <!--
            <bean id="profiler"
            class="cn.xiangyunsoft.business.service.SimpleProfiler"> order
            值可以決定通知的先后順序 ,與后面的order的值的大小,決定了是先通知再執行,還是先執行再通知 <property
            name="order" value="2" /> </bean>
        
    -->
        
    <bean id="transactionManager"
            class
    ="org.springframework.orm.hibernate3.HibernateTransactionManager">
            
    <property name="sessionFactory" ref="sessionFactory" />
        
    </bean>
        
    <aop:config>
            
    <!-- 此處的IService 是表示對所有實現IService接口的類管理事務 -->
            
    <aop:advisor
                
    pointcut="execution(* cn.xiangyunsoft.*.service..*ServiceImpl.*(..))"
                advice-ref
    ="txAdvice" />
            
    <!--
                加入之后事務不起作用> <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開頭的方法是只讀事務 -->
                
    <tx:method name="*" read-only="true" />
                
    <!--<tx:method name="find*" read-only="true" />-->
                
    <!--<tx:method name="load*" read-only="true" />-->
                
    <!-- 其他方法是默認,事務隔離級別為:保證一個事務修改的數據提交后才能被另外一個事務讀取 -->
                
    <tx:method name="save*" isolation="REPEATABLE_READ"
                    propagation
    ="REQUIRED" />
                
    <tx:method name="delete*" isolation="REPEATABLE_READ"
                    propagation
    ="REQUIRED" />
                    
            
    </tx:attributes>
        
    </tx:advice>
    </beans>


    一個注入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;
        }
    }


    這樣集成就完畢了。很簡單,很強大。




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

    評論:
    # re: JSF2.0 與Spring 3.0 集成 2010-07-19 17:53 | 任亮
    請問,博主用的什么服務器。怎么配置的啊。我現在在做一個jsf2.0的項目,想用jboss4.2服務器,但是配置不對,希望博主幫忙。  回復  更多評論
      
    # re: JSF2.0 與Spring 3.0 集成 2010-07-26 17:24 | Libo
    @任亮
    我使用的是glassfish,tomcat6 也可以。jboss4.2沒用過。  回復  更多評論
      
    主站蜘蛛池模板: 久青草视频97国内免费影视| 精品成人一区二区三区免费视频| 国产亚洲综合久久系列| 国产成人综合亚洲| 午夜无遮挡羞羞漫画免费| 亚洲一卡2卡3卡4卡乱码 在线| 青娱乐免费在线视频| 国产午夜鲁丝片AV无码免费| 亚洲另类激情综合偷自拍| 午夜精品射精入后重之免费观看 | mm1313亚洲精品无码又大又粗| 亚洲爆乳精品无码一区二区| 在线涩涩免费观看国产精品| 亚洲AV无码专区在线播放中文 | 国产乱子伦精品免费无码专区| 菠萝菠萝蜜在线免费视频| 最新亚洲成av人免费看| 女bbbbxxxx另类亚洲| 亚洲综合精品网站在线观看| 亚洲AV无码无限在线观看不卡| 日本黄色免费观看| 色老头综合免费视频| 久久亚洲综合色一区二区三区 | 最近中文字幕大全免费视频| 浮力影院亚洲国产第一页| 久久精品国产免费| 亚洲天堂中文字幕在线观看| 国产大片51精品免费观看| 亚洲中文字幕在线无码一区二区 | 在线观看人成网站深夜免费| 婷婷国产偷v国产偷v亚洲| 奇米影视亚洲春色| 日本在线高清免费爱做网站| 亚洲精品无码成人片久久不卡 | 亚洲香蕉网久久综合影视| 性xxxx视频免费播放直播| 亚洲精品色播一区二区| 亚洲中文字幕无码中文字在线| 免费国产污网站在线观看15| 亚洲AV无码不卡在线播放| 97在线线免费观看视频在线观看|