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

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 中文字幕久精品免费视频| 黄色三级三级三级免费看| 久久国产色AV免费观看| 黑人大战亚洲人精品一区| xvideos永久免费入口| 日韩一卡2卡3卡4卡新区亚洲| 羞羞网站在线免费观看| 亚洲AV无码一区二区三区国产| 理论片在线观看免费| 亚洲国产精品专区在线观看 | 亚洲欧洲日产国码无码网站| 一级特黄a免费大片| 国外亚洲成AV人片在线观看| 99热在线日韩精品免费| 亚洲AV日韩AV永久无码免下载| 99re视频精品全部免费| 亚洲综合色区中文字幕| 国产精品免费小视频| jizz免费一区二区三区| 久久亚洲国产成人精品性色| 国产a视频精品免费观看| 亚洲中文字幕久久精品无码A| 日日夜夜精品免费视频| 国产成人精品免费视频大全| 久久精品国产亚洲av四虎| 青娱分类视频精品免费2| 国产成人+综合亚洲+天堂| 亚洲色精品88色婷婷七月丁香| 免费国产污网站在线观看15 | 可以免费观看一级毛片黄a| 久久久久免费视频| 亚洲无人区视频大全| 免费一级肉体全黄毛片| 很黄很污的网站免费| 亚洲人成www在线播放| 亚洲色婷婷综合开心网| 97碰公开在线观看免费视频| 国产成人精品亚洲| 亚洲国产香蕉碰碰人人| 四虎成人免费观看在线网址| 国产成人免费ā片在线观看老同学|