欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ssh+注解框架配置文件

程序员文章站 2022-04-30 12:05:03
...

web.xml

<!--全局参数-------------------------------------------------------------------->
<context-param>
 
      <param-name>contextConfigLocation</param-name>
 
      <param-value>/WEB-INF/classes/applicationContext*.xml</param-value>
 
 </context-param>
 
 <!-- 配置Spring的监听器,用于初始化ApplicationContext对象 --------------------------->  
  <listener>  
    <listener-class>org.springframework.web.context.ContextLoaderListener</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.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  
    <init-param>  
      <param-name>filterConfig</param-name>  
      <param-value>classpath:struts.xml</param-value>  
    </init-param>  

    <!-- 自动扫描action -->  
    <init-param>  
      <param-name>actionPackages</param-name>  
      <param-value>com.ssh</param-value>  
    </init-param>  
  </filter>  

  <filter-mapping>  
    <filter-name>struts2</filter-name>  
    <url-pattern>/*</url-pattern>  
  </filter-mapping>  
<!--解决中文乱码问题  ----------------------------------------------------------->
  <filter>
  	<filter-name>characterEncoding</filter-name>
  	<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  	<init-param>
  		<param-name>encoding</param-name>
  		<param-value>UTF-8</param-value>
  	</init-param>
  </filter>
  <filter-mapping>
  	<filter-name>characterEncoding</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>
<!--设置hibernate的延迟加载问题---------------------------------------------->
<filter>
  	<filter-name>openSession</filter-name>
  	<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
  	<filter-name>openSession</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>  

applicationContext.xml

<!-- 加载jdbc属性文件,如果有的话 -------------------------------------------------->
   <context:property-placeholder location="classpath:db.properties"/> 

<!-- 自动扫描与装配bean ------------------------------------------------------>      
    <context:component-scan base-package="com.tgb.ssh"></context:component-scan>  
 <!--引入注解解析器  ---------------------------------------------------------------->
     <context:annotation-config/>    

<!-- dbcp配置 ------------------------------------------------------------------->    
    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">      
        <property name="driverClassName">    
            <value>com.mysql.jdbc.Driver</value>    
        </property>    
        <property name="url">    
            <value>jdbc:mysql://127.0.0.1:3307/ssh</value>    
        </property>    
        <property name="username">    
            <value>root</value>    
        </property>    
        <property name="password">    
            <value>123456</value>    
        </property>    
    </bean>    

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">    
        <property name="dataSource">    
            <ref local="dataSource" />    
        </property>    
        <property name="hibernateProperties">    
            <props>    
                <!--配置Hibernate的方言-->    
                <prop key="hibernate.dialect">    
                 org.hibernate.dialect.MySQLDialect    
                </prop>                    
                <prop key="hibernate.hbm2ddl.auto">update</prop>    

                <!--格式化输出sql语句-->    
                <prop key="hibernate.show_sql">true</prop>    
                <prop key="hibernate.format_sql">true</prop>      
                <prop key="hibernate.use_sql_comments">false</prop>      
            </props>    
        </property>    

<!--自动扫描实体 ---------------------------------------------------------------------->    
        <property name="packagesToScan"  value="com.tgb.ssh.model" />    
    </bean>    

<!-- 用注解来实现事务管理 ------------------------------------------------------------->    
    <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">    
        <property name="sessionFactory" ref="sessionFactory"></property>          
    </bean>    
    <tx:annotation-driven transaction-manager="txManager"/>    

struts.xml

<struts>    

    <!-- 开启使用开发模式,详细错误提示 -->    
    <constant name="struts.devMode" value="true" />    
    <!-- 将对象交给spring管理 -->    
    <constant name="struts.objectFactory" value="spring" />    
    <!-- 指定资源编码类型 -->    
    <constant name="struts.i18n.encoding" value="UTF-8" />     
    <!-- 指定每次请求到达,重新加载资源文件 -->    
    <constant name="struts.i18n.reload" value="false" />    
    <!-- 指定每次配置文件更改后,自动重新加载 -->    
    <constant name="struts.configuration.xml.reload" value="false" />    
    <!-- 默认后缀名 -->    
    <constant name="struts.action.extension" value="action," />   
    <!-- 指定上传文件的大小上限 -->
   <constant name="struts.multipart.maxSize" value="209715200" />
    <!-- 浏览器是否缓存静态内容,生产环境下需要设置为true -->
   <constant name="struts.serve.static.browserCache" value="true" />
    <!-- 开启动态方法调用 -->
    <constant name="struts.enable.DynamicMethodInvocation"value="false" />
</struts>