posts - 431,  comments - 344,  trackbacks - 0
          公告
           Don't Repeat Yourself
          座右銘:you can lose your money, you can spent all of it, and if you work hard you get it all back. But if you waste your time, you're never gonna get it back.
          公告本博客在此聲明部分文章為轉(zhuǎn)摘,只做資料收集使用。


          微信: szhourui
          QQ:109450684
          Email
          lsi.zhourui@gmail.com
          <2007年3月>
          25262728123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          留言簿(15)

          隨筆分類(1019)

          文章分類(3)

          文章檔案(21)

          收藏夾

          Link

          好友博客

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 863948
          • 排名 - 44

          最新評(píng)論

          閱讀排行榜

          1.讀取屬性文件
          <!-- for properties files -->
           <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
             <list>
              <value>classpath:*.properties</value>
             </list>
            </property>
           </bean>

          2.配置數(shù)據(jù)源
          <!-- for dataSource -->
          <bean id="dataSource"
            class="com.mchange.v2.c3p0.ComboPooledDataSource
            destroy-method="close">
            <property name="driverClass" value="${jdbc.driver}" />
            <property name="jdbcUrl" value="${jdbc.url}" />

            <property name="properties">
             <props>
              <prop key="c3p0.minPoolSize">${hibernate.c3p0.minPoolSize}</prop>
              <prop key="hc3p0.maxPoolSize">${hibernate.c3p0.maxPoolSize}</prop>
              <prop key="hc3p0.timeout">${hibernate.c3p0.timeout}</prop>
              <prop key="c3p0.max_statement">${hibernate.c3p0.max_statement}</prop>
              <prop key="user">${jdbc.username}</prop>
              <prop key="password">${jdbc.password}</prop>
              <prop key="c3p0.testConnectionOnCheckout">true</prop>
             </props>
            </property>
           </bean>
          #Jdbc Configuration

          jdbc.driver=com.mysql.jdbc.Driver
          jdbc.url=jdbc:mysql://localhost/wsh?useUnicode=true&characterEncoding=utf-8
          jdbc.username=wsh
          jdbc.password=wsh

          hibernate.c3p0.minPoolSize=2
          hibernate.c3p0.maxPoolSize=10
          hibernate.c3p0.timeout=100
          hibernate.c3p0.max_statement=900

          注:當(dāng)然還有很多例如"org.apache.commons.dbcp.BasicDataSource"
          <bean id="dataSource"
            class="org.apache.commons.dbcp.BasicDataSource"
            destroy-method="close">
            <property name="driverClassName"
             value="${jdbc.driverClassName}" />
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
           </bean>
          jdbc.driverClassName=org.gjt.mm.mysql.Driver
          jdbc.url=jdbc:mysql://172.19.30.178:3306/wsh?useUnicode=true&characterEncoding=utf-8
          jdbc.username=wsh
          jdbc.password=wsh

          hibernate.dialect=org.hibernate.dialect.MySQLDialect
          hibernate.show_sql=true
          hibernate.hbm2ddl.auto=update

          3.sessionFactory配置
          <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />

            <property name="mappingDirectoryLocations">
             <list>
              <value>classpath:/com/rain/wsh/model/</value>
             </list>
            </property>

            <property name="hibernateProperties">
             <props>
              <prop key="hibernate.dialect">
               org.hibernate.dialect.MySQLDialect
              </prop>
              <prop key="hibernate.show_sql">false</prop>
              <!-- <prop key="hibernate.cache.use_query_cache">false</prop> -->
              <!-- prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop-->
              <prop key="hibernate.connection.provider_class">
               org.hibernate.connection.C3P0ConnectionProvider
              </prop>
              <prop key="hibernate.generate_statistics">false</prop>
             </props>
            </property>
           </bean>

          <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
            singleton="true">
            <property name="dataSource">
             <ref local="dataSource" />
            </property>
            <property name="mappingResources">
             <list>
              <value>
               com/rain/study/model/User.hbm.xml
              </value>
             </list>
            </property>
            <property name="hibernateProperties">
             <props>
              <prop key="hibernate.dialect">
               ${hibernate.dialect}
              </prop>
              <prop key="hibernate.show_sql">
               ${hibernate.show_sql}
              </prop>
              <!--   <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>-->
             </props>
            </property>
           </bean>

          4.transactionManager配置
          <!-- Hibernate transaction processing -->
           <bean id="transactionManager"
            class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory">
             <ref local="sessionFactory" />
            </property>
           </bean>

          5.baseTxService配置(Service的代理工廠)
          <bean id="baseTxService" abstract="true"
            class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager" ref="transactionManager" />
            <property name="transactionAttributes">
             <props>
              <prop key="create*">PROPAGATION_REQUIRED</prop>
              <prop key="update*">PROPAGATION_REQUIRED</prop>
              <prop key="delete*">PROPAGATION_REQUIRED</prop>
              <prop key="get*">PROPAGATION_REQUIRED, readOnly</prop>
              <prop key="*">PROPAGATION_REQUIRED</prop>
             </props>
            </property>
            <property name="postInterceptors" ref="methodSecurityInterceptor" />
           </bean>
          methodSecurityInterceptor則是acegi中的攔截器(注:見下一篇acegi配置)

          6.Service配置
          <bean id="userService" parent="baseTxService">
              <property name="target">
                <bean class="com.rain.wsh.service.impl.UserServiceImpl"/>
              </property>
          </bean>

          注意:為了更加的是配置文件清晰,可以把spring的配置文件分成多個(gè)配置文件,例如(applicationContext-hibernate.xml,applicationContext-service.xml等),然后在web.xml中配置的時(shí)候?qū)懗?
           <context-param>
                  <param-name>contextConfigLocation</param-name>
                  <param-value>/WEB-INF/applicationContext*.xml</param-value>
           </context-param>



          posted on 2007-03-29 10:10 周銳 閱讀(462) 評(píng)論(0)  編輯  收藏 所屬分類: Spring
          主站蜘蛛池模板: 岳阳县| 永仁县| 揭东县| 体育| 道真| 永州市| 壶关县| 固镇县| 华安县| 文登市| 罗城| 武威市| 建平县| 沙雅县| 和林格尔县| 青海省| 台中县| 昭觉县| 攀枝花市| 遂溪县| 永定县| 兴义市| 长岭县| 龙门县| 克什克腾旗| 凤阳县| 宜宾县| 呈贡县| 平果县| 陆丰市| 晋州市| 长宁区| 巩留县| 贵溪市| 千阳县| 西畴县| 大悟县| 双桥区| 江北区| 新沂市| 如东县|