posts - 0, comments - 77, trackbacks - 0, articles - 356
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

【spring+hibernate学习文档】---配置篇

Posted on 2006-11-03 17:36 semovy 阅读(647) 评论(0)  编辑  收藏 所属分类: J2EE综合

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app 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/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
 <display-name>framework</display-name>

 <description>framework sample application</description>

 <!--
   - Key of the system property that should specify the root directory of this
   - web app. Applied by WebAppRootListener or Log4jConfigListener.
   -->
 <context-param>
  <param-name>webAppRootKey</param-name>
  <param-value>framework.root</param-value>
 </context-param>

 <!--
   - Location of the Log4J config file, for initialization and refresh checks.
   - Applied by Log4jConfigListener.
   -->
 <context-param>
  <param-name>log4jConfigLocation</param-name>
  <param-value>/WEB-INF/log4j.properties</param-value>
 </context-param>
 
        <filter>
           <filter-name>Set Character Encoding</filter-name>
           <filter-class>cn.rhui.framework.common.filter.SetCharacterEncodingFilter</filter-class>
           <init-param>
               <param-name>encoding</param-name>
               <param-value>GBK</param-value>
           </init-param>
        </filter>
       
        <filter-mapping>
           <filter-name>Set Character Encoding</filter-name>
           <url-pattern>/*</url-pattern>
        </filter-mapping>
   
 
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml
   /WEB-INF/dataAccessContext-local.xml
  </param-value>   
 </context-param>

 <!--
   - Configures Log4J for this web app.
   - As this context specifies a context-param "log4jConfigLocation", its file path
   - is used to load the Log4J configuration, including periodic refresh checks.
   -
   - Would fall back to default Log4J initialization (non-refreshing) if no special
   - context-params are given.
   -
   - Exports a "web app root key", i.e. a system property that specifies the root
   - directory of this web app, for usage in log file paths.
   - This web app specifies "petclinic.root" (see log4j.properties file).
   -->
 <!-- Leave the listener commented-out if using JBoss -->
 
 <listener>
  <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 </listener>
 
        <servlet>
  <servlet-name>context</servlet-name>
  <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
        </servlet>


  <servlet>
  <servlet-name>action</servlet-name>
  <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
  
  <init-param>
       <param-name>config</param-name>
       <param-value>/WEB-INF/struts-config.xml</param-value>
  </init-param>
  
         <init-param>
                   <param-name>config/workflow</param-name>
                   <param-value>/WEB-INF/workflow/struts-config.xml</param-value>
         </init-param>
           
         <init-param>
                   <param-name>config/testflow</param-name>
                   <param-value>/WEB-INF/testflow/struts-config.xml</param-value>
         </init-param>                 
  <load-on-startup>2</load-on-startup>
 </servlet>

 <!--
   - Maps the petclinic dispatcher to *.htm. All handler mappings in
   - petclinic-servlet.xml will by default be applied to this subpath.
   - If a mapping isn't a /* subpath, the handler mappings are considered
   - relative to the web app root.
   -
   - NOTE: A single dispatcher can be mapped to multiple paths, like any servlet.
   -->
 <servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>*.do</url-pattern>
 </servlet-mapping>

 <session-config>
  <session-timeout>30</session-timeout>
 </session-config>

 <welcome-file-list>
  <!-- Redirects to "welcome.htm" for dispatcher handling -->
  <!--welcome-file>index.jsp</welcome-file-->
  <welcome-file>default.jsp</welcome-file>
 </welcome-file-list>

 <error-page>
  <exception-type>java.lang.Exception</exception-type>
  <!-- Displays a stack trace -->
  <location>/WEB-INF/jsp/uncaughtException.jsp</location>
 </error-page>
 <jsp-config>  
            <taglib>
               <taglib-uri>/WEB-INF/page-tag.tld</taglib-uri>
               <taglib-location>/WEB-INF/tld/page-tag.tld</taglib-location>
            </taglib>  
 
    <taglib>
               <taglib-uri>core</taglib-uri>
               <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
           </taglib>
   
    <taglib>
        <taglib-uri>/WEB-INF/tld/struts-bean.tld</taglib-uri>
        <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>  
    </taglib>
 
    <taglib>
  <taglib-uri>/WEB-INF/tld/struts-html.tld</taglib-uri>
  <taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>  
    </taglib>
 
    <taglib>
  <taglib-uri>/WEB-INF/tld/struts-logic.tld</taglib-uri>
  <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>  
    </taglib>
     <taglib>
  <taglib-uri>t</taglib-uri>
  <taglib-location>/WEB-INF/tld/t.tld</taglib-location>  
    </taglib>
 </jsp-config>

 <!--
  - Reference to Petclinic database.
  - Only needed if not using a local DataSource but a JNDI one instead.
  -->
 <!--
 <resource-ref>
  <res-ref-name>jdbc/framework</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
 </resource-ref>
 -->

</web-app>

-----------------applicationContext.xml-------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<!--
  - Application context definition for framework.
 -->
<beans>

 <!-- ========================= RESOURCE DEFINITIONS ========================= -->
 
 <!-- Configurer that replaces ${...} placeholders with values from a properties file -->
 <!-- (in this case, JDBC-related settings for the dataSource definition below) -->
 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location"><value>/WEB-INF/jdbc.properties</value></property>
 </bean>


 <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory"><ref bean="sessionFactory"/></property>
 </bean>

 <!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->
 <!--
 <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
 -->
 <!-- id generator -->
 <bean id="idGenerateService" parent="baseTransactionProxyFactoryBean">
  <property name="target">
   <bean class="cn.rhui.framework.idgenerator.service.IdGenerateServiceImpl" autowire="byName"/>
  </property> 
 </bean>
 <bean id="generate" class="cn.rhui.framework.idgenerator.Generator">
  <property name="idService">
   <ref local="idGenerateService"></ref>
  </property>
  <property name="path"><value>${generator.path}</value></property>
 </bean>
 <!-- end id generator -->
 <!--
  - Transactional proxy for Petclinic's central data access object.
  -
  - Defines specific transaction attributes with "readOnly" markers,
  - which is an optimization that is particularly valuable with Hibernate
  - (to suppress unnecessary flush attempts for read-only operations).
  -
  - Note that in a real-life app with multiple transaction proxies,
  - you will probably want to use parent and child bean definitions
  - as described in the manual, to reduce duplication.
    -->
 <bean id="baseTransactionProxyFactoryBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
  <property name="transactionManager"><ref local="transactionManager"/></property>
  <property name="transactionAttributes">
   <props>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="select*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="create*">PROPAGATION_REQUIRED</prop>
   </props>
  </property>
 </bean>

</beans>

------------dataAccessCotext-local.xml--------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

    <!-- ========================= owners bean ========================= -->
 <!-- Local DataSource that works in any environment -->
 <!-- Note that DriverManagerDataSource does not pool; it is not intended for production -->
 <!-- See JPetStore for an example of using Commons DBCP BasicDataSource as alternative -->
 <!-- See Image Database for an example of using C3P0 ComboPooledDataSource as alternative -->
 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName"><value>${jdbc.driverClassName}</value></property>
  <property name="url"><value>${jdbc.url}</value></property>
  <property name="username"><value>${jdbc.username}</value></property>
  <property name="password"><value>${jdbc.password}</value></property>
 </bean>

 <!-- JNDI DataSource for J2EE environments -->
 <!--
 <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
  <property name="jndiName"><value>java:comp/env/jdbc/petclinic</value></property>
 </bean>
 -->

 <!-- Hibernate SessionFactory -->
 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource"><ref local="dataSource"/></property>
   <property name="schemaUpdate">
    <value>true</value>
   </property>
  <property name="mappingResources">
   <list>
    <value>cn/rhui/framework/test/domain/Owners.hbm.xml</value>
      <value>cn/rhui/framework/idgenerator/vo/SysGenerateId.hbm.xml</value>

   </list>
  </property>
  <property name="hibernateProperties">
   <props>
          <prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
                  <prop key="hibernate.dbcp.maxActive">100</prop>
    <prop key="hibernate.dbcp.whenExhaustedAction">1</prop>
    <prop key="hibernate.dbcp.maxWait">120000</prop>
    <prop key="hibernate.dbcp.maxIdle">10</prop>
    <prop key="hibernate.dbcp.ps.maxActive">100</prop>
    <prop key="hibernate.dbcp.ps.whenExhaustedAction">1</prop>
    <prop key="hibernate.dbcp.ps.maxWait">120000</prop>
    <prop key="hibernate.dbcp.ps.maxIdle">10</prop>
    <!--prop key="hibernate.dbcp.validationQuery">select 1 from AclUser</prop-->
    <prop key="hibernate.dbcp.testOnBorrow">true</prop>
    <prop key="hibernate.dbcp.testOnReturn">false</prop>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.connection.pool_size">10</prop>
    <prop key="hibernate.cache.use_query_cache">true</prop>
    <!--prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.Provider</prop-->
    <prop key="hibernate.use_outer_join">true</prop>
    <prop key="hibernate.max_fetch_depth">3</prop>
    <prop key="hibernate.jdbc.fetch_size">100</prop>
    <prop key="hibernate.jdbc.batch_size">30</prop>
    <prop key="hibernate.default_batch_fetch_size">50</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</prop>
   </props>
  </property>
 </bean>

    <bean id="ownersDao" class="cn.rhui.framework.test.dao.impl.OwnersImpl" autowire="byName"/>

</beans>



只有注册用户登录后才能发表评论。


网站导航: