ssh框架学习之配置文件大全

框架所需配置文件大集合

spring配置文件
(1)配置文件所需的标准(xsd)文档结构
< 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:tx = "http://www.springframework.org/schema/tx" xmlns:aop = "http://www.springframework.org/schema/aop"
      xsi:schemaLocation = "http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd"
      default-autowire = "byName">
(2)配置文件内部
      <!-- 扫描哪些包下面的哪些类使用注解 -->
      < context:component-scan base-package = "com.chenfeng" />
      <!-- 配置hibernate5需要配置数据库的连接信息而3,4则不需要 -->
      < bean id = "dataSource"    class = "org.springframework.jdbc.datasource.DriverManagerDataSource" >
          < property name = "driverClassName" value = "com.mysql.jdbc.Driver" />
          < property name = "url" value = "jdbc:mysql://localhost:3306/ssh" />
          < property name = "username" value = "root" />
          < property name = "password" value = "root" />
      </ bean >
         
      < bean id = "sessionFactory" class = "org.springframework.orm.hibernate5.LocalSessionFactoryBean" >
          <!-- 调用并开启hibernate配置文件 -->
          < property name = "configLocation" value = "classpath:hibernate.cfg.xml" />
          <!-- 设置hibernate的数据库官方支持语言 显示格式 -->
          < property name = "hibernateProperties" >
               < props >
                   < prop key = "hibernate.dialect" > org.hibernate.dialect.MySQLDialect </ prop >
                   < prop key = "hibernate.show_sql" > true </ prop >
                   < prop key = "hibernate.format_sql" > true </ prop >
               </ props >
          </ property >
      </ bean >
      <!-- 配置spring的事务管理器 并开启-->
      < bean id = "transactionManager" class = "org.springframework.orm.hibernate5.HibernateTransactionManager" >
      </ bean >
      <!-- 那些方法需要开启 rollback-for抛出那些异常需要是spring回滚
      默认的是RunTimeException
      name=""以什么开头的方法要开启事物
      requireed:需要开启事物 
      transaction-manager="transactionManager":指定事务管理器
      -->
      < tx:advice transaction-manager = "transactionManager" id = "txAdvice" >
           < tx:attributes >
               < tx:method name = "save*" propagation = "REQUIRED" rollback-for = "Exception" />
               < tx:method name = "update*" propagation = "REQUIRED" rollback-for = "Exception" />
               < tx:method name = "delete*" propagation = "REQUIRED" rollback-for = "Exception" />
               < tx:method name = "*" read-only = "true" />
           </ tx:attributes >
      </ tx:advice >
      < aop:config >
           < aop:pointcut expression = "execution(* com.chenfeng.dao.Impl.*.*(..))" id = "pointcut" />
           < aop:advisor advice-ref = "txAdvice" pointcut-ref = "pointcut" />
      </ aop:config >

Hibernate的配置文件
(1)hibernate的dtd文件 XML约束模式语言
<! DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" >
(2)Hibernate的配置
< hibernate-configuration >
      < session-factory >
          <!-- 驱动 -->
          < property name = "hibernate.connection.driver_class" > com.mysql.jdbc.Driver </ property >
          <!-- url -->
          < property name = "hibernate.connection.url" >
              jdbc:mysql://localhost:3306/ssh
          </ property >
          <!-- 用户名 -->
          < property name = "hibernate.connection.username" > root </ property >
          <!-- 密码 -->
          < property name = "hibernate.connection.password" > root </ property >
          <!-- 官方语言 -->
          < property name = "hibernate.dialect" > org.hibernate.dialect.MySQLDialect </ property >
          <!-- showSQL -->
          < property name = "hibernate.show_sql" > true </ property >
          <!-- formatSQL -->
          < property name = "hibernate.format_sql" > true </ property >    
          < mapping resource = "com/chenfeng/pojo/admins.hbm.xml" />
          < mapping resource = "com/chenfeng/pojo/role.hbm.xml" />
      </ session-factory >
</ hibernate-configuration >
struts的配置文件
(1)dtd文件约束
<! DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd" >

(2)文件的配置相关
父文件structs只认struts.xml
< struts >
      < constant name = "struts.devMode" value = "true" ></ constant >
      < constant name = "struts.action.extension" value = "htm" ></ constant >
      < include file = "struts_*.xml" ></ include >
</ struts >
子文件通过父文件调用
< struts >
      < package name = "head_pack" extends = "struts-default" namespace = "/head" strict-method-invocation = "false" >
          < action name = "admins_*" class = "userAction" method = "{1}" >
               < result name = "{1}" >
                  /WEB-INF/jsp/head/{1}.jsp
               </ result >
          </ action >
      </ package >         
</ struts >
web.xml文件的配置
<? xml version = "1.0" encoding = "UTF-8" ?>
< web-app xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
      xmlns = "http://java.sun.com/xml/ns/javaee"
      xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      id = "WebApp_ID" version = "3.0" >
      < display-name > ssh_dom </ display-name >
      <!-- 配置opensessionviem开始 -->
      < filter >  
           < filter-name > OpenSessionInViewFilter </ filter-name >
           < filter-class > org.springframework.orm.hibernate5.support.OpenSessionInViewFilter </ filter-class >
      </ filter >
      < filter-mapping >
           < filter-name > OpenSessionInViewFilter </ filter-name >
          < url-pattern > /* </ url-pattern >
      </ filter-mapping >
      <!-- 配置opensessionviem结束 -->
      <!-- 加载struts开始 -->
      < filter >
        < filter-name > action2 </ filter-name >
        < filter-class > org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter </ filter-class >
    </ filter >
    < filter-mapping >
        < filter-name > action2 </ filter-name >
        < url-pattern > /* </ url-pattern >
    </ filter-mapping >
      <!--加载struts结束  -->
      <!-- 加载spring监听器开始 -->
      < context-param >
          < param-name > contextConfigLocation </ param-name >
           < param-value > classpath:spring/applicationContext_*.xml </ param-value >
      </ context-param >
      < listener >
           < listener-class > org.springframework.web.context.ContextLoaderListener </ listener-class >
      </ listener >
      <!-- 加载spring监听器结束 -->
      < welcome-file-list >
          < welcome-file > index.html </ welcome-file >
          < welcome-file > index.htm </ welcome-file >
          < welcome-file > index.jsp </ welcome-file >
          < welcome-file > default.html </ welcome-file >
          < welcome-file > default.htm </ welcome-file >
          < welcome-file > default.jsp </ welcome-file >
      </ welcome-file-list >
</ web-app >
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值