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

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

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

    【原】spring 2.5--注解

    spring 2.5 權威學習資料:http://www.ibm.com/developerworks/cn/java/j-lo-spring25-ioc/

    剛剛做了個項目需要spring2.5的注解注入機制,順便把spring2.5注解的配置文件記錄下來。

    一 準備工作
        導入Jar包:


    二 配置文件:
    1 web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation
    ="http://java.sun.com/xml/ns/j2ee 
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

        
    <!--  Spring ApplicationContext -->
        
    <listener>
            
    <listener-class>
                org.springframework.web.context.ContextLoaderListener
            
    </listener-class>
        
    </listener>
        
    <!--session scope no Spring bean  -->
        
    <listener>
            
    <listener-class>
                org.springframework.web.context.request.RequestContextListener
            
    </listener-class>
        
    </listener>
        
        
    <context-param>
            
    <param-name>contextConfigLocation</param-name>
            
    <param-value>
                classpath:
    /applicationContext.xml
            
    </param-value>
        
    </context-param>
        
        
        
    <!-- struts2配置文件 -->
        
    <filter>
            
    <filter-name>struts2</filter-name>
            
    <filter-class>
                org.apache.struts2.dispatcher.FilterDispatcher
            
    </filter-class>
        
    </filter>
        
    <filter-mapping>
            
    <filter-name>struts2</filter-name>
            
    <url-pattern>/*</url-pattern>
        </filter-mapping>
        
        <welcome-file-list>
            <welcome-file>main.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

    2 struts.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        
    "http://struts.apache.org/dtds/struts-2.0.dtd">

    <struts>


        
    <package name="data_import_manager" extends="struts-default" >
        
            
    <action name="importData">
                
    <result>/import_taxdata.jsp</result>
            
    </action>

            
    <action name="taxEnterpriseImport" class="taxImportAction"
                method
    ="taxEnterprise" >
                
    <result name="success">/import_taxdata.jsp</result>
            
    </action>
            
    <action name="taxInfoImport" class="taxImportAction"
                method
    ="taxInfo" >
                
    <result name="error">/import_taxdata.jsp</result>
                
    <result name="success">/success.jsp</result>
            
    </action>
            
        
    </package>


    </struts>

    3 application.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:context
    ="http://www.springframework.org/schema/context" 
        xmlns:aop
    ="http://www.springframework.org/schema/aop"
        xmlns:tx
    ="http://www.springframework.org/schema/tx"
        xsi:schemaLocation
    ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

        
    <context:component-scan base-package="com.btwob.squall.bmis" />


        
    <!-- 數據源 -->
        
    <bean id="default_dataSource"
            
    class="org.apache.commons.dbcp.BasicDataSource"
            destroy
    -method="close">
            
    <property name="driverClassName"
                value
    ="net.sourceforge.jtds.jdbc.Driver" />
            
    <property name="url"
                value
    ="jdbc:jtds:sqlserver://192.168.1.111:1433/BuildingMIS" />
            
    <property name="username" value="sa" />
            
    <property name="password" value="root" />
            
    <property name="maxActive" value="100" />
            
    <property name="maxIdle" value="30"></property>
            
    <property name="maxWait" value="500" />
        
    </bean>


        
    <bean id="sessionFactory"
            
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            
    <!-- 載入數據源 -->
            
    <property name="dataSource">
                
    <ref bean="default_dataSource" />
            
    </property>
            
    <property name="hibernateProperties">
                
    <props>
                    
    <prop key="hibernate.dialect">
                        org.hibernate.dialect.SQLServerDialect
                    
    </prop>
                    
    <prop key="show_sql">true</prop>
                
    </props>
            
    </property>
            
    <property name="mappingResources">
                
    <value>com/btwob/squall/bmis/model/Tax.hbm.xml</value>
            
    </property>
        
    </bean>



        
    <!-- hibernateTemplate -->
        
    <bean id="hibernateTemplate"
            
    class="org.springframework.orm.hibernate3.HibernateTemplate">
            
    <property name="sessionFactory">
                
    <ref bean="sessionFactory" />
            
    </property>
        
    </bean>
        
        
        
    </beans>

    三 注解注入文件:
    1 dao實現類:
    @Scope("singleton")
    @Repository(
    "taxDao")
    public class TaxDao implements ITaxDao {

        @Autowired
        
    private HibernateTemplate hibernateTemplate;

    public void saveTax(Tax tax) throws Exception {
            hibernateTemplate.save(tax);
            hibernateTemplate.flush();
        }

    }
    2 serivce實現類:
    @Service("taxService")
    public class TaxService implements ITaxService {

        @Autowired
        @Qualifier(
    "taxDao")
        
    private ITaxDao taxDao;
            
    public void saveTaxService(Tax tax) {
            
    try {
                taxDao.saveTax(tax);
            } 
    catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    3 action類:

    @SuppressWarnings("serial")
    @Scope(
    "prototype")
    @Controller(
    "taxImportAction")
    public class TaxImportAction extends BaseAction {

        @Autowired
        @Qualifier(
    "taxService")
        
    private ITaxService taxService;

        
    public TaxImportAction() {
            
    super();
        }

        @Override
        
    public String execute() {
            
    return SUCCESS;
        }
        
    public String taxEnterprise() throws Exception {return success;
    }
        @SuppressWarnings(
    "unchecked")
        
    public String taxInfo() throws Exception {return success;
    }
    }



    posted on 2010-01-24 22:16 龍櫻 閱讀(3014) 評論(2)  編輯  收藏 所屬分類: 框架層

    評論

    # re: spring 2.5--注解 2010-01-25 09:42 咖啡妝

    你的項目的jar包也太瘋狂了吧 一大堆,重復的也很多,spring只需要 spring.jar 在spring3.X以后各個模塊裁分開編譯jar包。
    建議用spring2.X 的最后版本spring2.6 。有些功能spring2.5沒有而且有必要。spring3.x的想后兼容性會有問題。  回復  更多評論   

    # re: spring 2.5--注解 2010-02-05 17:32 傀儡守望者

    @咖啡妝
    JAR包,都是項目中需要的,已經把重復的刪除了。
      回復  更多評論   


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2010年1月>
    272829303112
    3456789
    10111213141516
    17181920212223
    24252627282930
    31123456

    導航

    統計

    常用鏈接

    留言簿(3)

    隨筆分類(13)

    隨筆檔案(13)

    文章分類(1)

    文章檔案(1)

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 中文字幕在线免费视频| 久久久久久99av无码免费网站 | 国产免费久久久久久无码| 亚洲国产AV无码专区亚洲AV| 久草视频免费在线| 美女一级毛片免费观看 | 成人免费观看男女羞羞视频| 亚洲VA中文字幕不卡无码| A在线观看免费网站大全| 亚欧国产一级在线免费| 亚洲欧洲日产国码www| www.亚洲精品.com| 18级成人毛片免费观看| 日韩精品免费一线在线观看| 亚洲美女视频一区| 国产成人精品久久亚洲| 免费观看成人毛片a片2008| 成人免费av一区二区三区| 亚洲精品456人成在线| 亚洲AV无码一区东京热久久 | 最近最好的中文字幕2019免费| 一级a性色生活片久久无少妇一级婬片免费放| 亚洲va无码专区国产乱码| 国产91在线免费| 国产免费的野战视频| 91精品成人免费国产| 成人亚洲国产精品久久| 精品久久亚洲中文无码| 亚洲国产精品久久| 精品亚洲一区二区三区在线观看 | 亚洲男人天堂2022| 亚洲国产老鸭窝一区二区三区| 国产三级免费电影| 成年免费大片黄在线观看岛国| 久久免费福利视频| caoporm碰最新免费公开视频| 亚洲精品久久无码| 亚洲一级毛片在线观| 666精品国产精品亚洲| 久久久亚洲精品国产| 亚洲自偷自偷图片|