spring配置文件applicationContext.xml,放在resources下

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/tx
  10. http://www.springframework.org/schema/tx/spring-tx.xsd
  11. http://www.springframework.org/schema/context
  12. http://www.springframework.org/schema/context/spring-context.xsd
  13. http://www.springframework.org/schema/aop
  14. http://www.springframework.org/schema/aop/spring-aop.xsd">
  15.  
  16. <!--Spring配置文件的核心点( 1、数据源 2、与mybatis的整合 3、事务控制 )-->
  17.  
  18. <!--业务逻辑组件扫描进来-->
  19. <context:component-scan base-package="club.iashe">
  20. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  21. </context:component-scan>
  22.  
  23. <!--==================================================================================================================-->
  24. <!--数据源的配置-->
  25. <!--引入外部的配置文件-->
  26. <context:property-placeholder ignore-unresolvable="true" location="classpath:dbconfig.properties"/>
  27.  
  28. <!-- 数据库连接池c3p0配置数据源 -->
  29. <bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  30. <property name="jdbcUrl" value="${jdbc.jdbcUrl}"/>
  31. <property name="driverClass" value="${jdbc.driverClass}"/>
  32. <property name="user" value="${jdbc.user}"/>
  33. <property name="password" value="${jdbc.password}"/>
  34. </bean>
  35.  
  36. <!--==================================================================================================================-->
  37. <!--配置和mybatis整合-->
  38. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  39. <!--指定mybatis全局配置文件的位置-->
  40. <property name="configLocation" value="classpath:mybatis-config.xml"/>
  41. <!--指定数据源-->
  42. <property name="dataSource" ref="pooledDataSource"/>
  43. <!--指定mybatis映射文件的位置-->
  44. <property name="mapperLocations" value="classpath:mapper/*Mapper.xml"/>
  45. </bean>
  46.  
  47. <!--配置扫描器,将mybatis接口的实现,即DAO接口所在包名,加入到IOC容器中-->
  48. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  49. <!--扫描所有dao接口的实现,加入到IOC容器中-->
  50. <property name="basePackage" value="club.iashe.dao"/>
  51. </bean>
  52.  
  53. <!--配置一个可以执行批量的sqlSession-->
  54. <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" >
  55. <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"/>
  56. <!--<constructor-arg name="executorType" value="BATCH" />-->
  57. </bean>
  58.  
  59. <!--==================================================================================================================-->
  60. <!-- 事务控制的配置,spring声明式事务 -->
  61. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  62. <!--控制住数据源-->
  63. <property name="dataSource" ref="pooledDataSource"/>
  64. </bean>
  65.  
  66. <!--开启基于注解的事务/使用xml配置形式的事务(一般比较重要的都使用xml形式)-->
  67. <aop:config>
  68. <!--切入点表达式-->
  69. <aop:pointcut expression="execution(* club.iashe.service..*(..))" id="txPoint"/>
  70. <!--<aop:pointcut id="txPoint" expression="execution(* cn.crud.service..*(..))"/>-->
  71. <!--配置事务增强-->
  72. <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
  73. </aop:config>
  74.  
  75. <!--配置事务增强,也就是事务如何切入-->
  76. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  77. <tx:attributes>
  78. <!--代表这个切入点的所有方法都是事务方法-->
  79. <tx:method name="*"/>
  80. <!--以get开始的所有方法,进行调优-->
  81. <tx:method name="get*" read-only="true"/>
  82. </tx:attributes>
  83. </tx:advice>
  84. <!--==================================================================================================================-->
  85. </beans>

springMVC配置文件,dispatcherServlet-servlet.xml,放在WEB-INF下

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://www.springframework.org/schema/context
  9. http://www.springframework.org/schema/context/spring-context.xsd
  10. http://www.springframework.org/schema/mvc
  11. http://www.springframework.org/schema/mvc/spring-mvc.xsd">
  12.  
  13. <!--两个标准配置-->
  14. <!--将springMVC不能处理的请求交给tomcat-->
  15. <mvc:default-servlet-handler />
  16. <!--能支持springMVC一些更高级的功能,注释替代XML配置,jrs303校验,快捷的ajax,映射动态请求-->
  17. <!--<mvc:annotation-driven />-->
  18. <!-- 使用fastjson替换springMVC默认的Jackson -->
  19. <mvc:annotation-driven>
  20. <mvc:message-converters register-defaults="true">
  21. <!-- 配置fastjson支持 -->
  22. <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
  23. <property name="defaultCharset" value="UTF-8" />
  24. <property name="supportedMediaTypes">
  25. <list>
  26. <value>text/html;charset=UTF-8</value>
  27. <value>application/json</value>
  28. </list>
  29. </property>
  30. </bean>
  31. </mvc:message-converters>
  32. </mvc:annotation-driven>
  33.  
  34. <!--
  35. springMVC的配置文件,包含网站跳转逻辑的控制、配置
  36. 注释改掉默认扫描所有use-default-filters,设为false
  37. -->
  38. <context:component-scan base-package="club.iashe" use-default-filters="false">
  39. <!--只扫描控制器-->
  40. <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  41. </context:component-scan>
  42.  
  43. <!-- 配置视图解析器,方便页面返回信息 -->
  44. <!-- 配置 HTML 视图解析器 -->
  45. <!-- html视图解析器,必须先配置freemarkerConfig,html没有prefix属性 -->
  46. <!--<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
  47. <property name="resourceLoader">
  48. <value>/html/</value>
  49. </property>
  50. </bean>
  51. <bean id="htmlViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
  52. <property name="suffix" value="html" />
  53. <property name="order" value="0"/>
  54. <property name="contentType" value="text/html;charset=UTF-8" />
  55. </bean>-->
  56. <!-- 配置 jsp 视图解析器 -->
  57. <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  58. <!--<property name="prefix" value="WEB-INF/views/" /> &lt;!&ndash;前缀&ndash;&gt;-->
  59. <property name="prefix" value="WEB-INF/admin/views/" /> <!--前缀-->
  60. <property name="suffix" value=".jsp" /> <!--后缀-->
  61. </bean>
  62.  
  63. </beans>

mybatis配置文件,mybatis-config.xml,resources下

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
  3. <configuration>
  4.  
  5. <settings>
  6. <!-- Globally enables or disables any caches configured in any mapper under this configuration -->
  7. <setting name="cacheEnabled" value="false"/>
  8. <!-- Sets the number of seconds the driver will wait for a response from the database -->
  9. <setting name="defaultStatementTimeout" value="5"/>
  10. <!-- Enables automatic mapping from classic database column names A_COLUMN to camel case classic Java property names aColumn -->
  11. <!-- 数据库下划线转为驼峰 -->
  12. <setting name="mapUnderscoreToCamelCase" value="true"/>
  13. <!-- Allows JDBC support for generated keys. A compatible driver is required.
  14. This setting forces generated keys to be used if set to true,
  15. as some drivers deny compatibility but still work -->
  16. <setting name="useGeneratedKeys" value="true"/>
  17. </settings>
  18.  
  19. <!-- Continue editing here -->
  20. <!--起别名-->
  21. <typeAliases>
  22. <package name="club.iashe.pojo" />
  23. </typeAliases>
  24.  
  25. <!--配置PageHelper插件-->
  26. <plugins>
  27. <!-- com.github.pagehelper为PageHelper类所在包名 -->
  28. <plugin interceptor="com.github.pagehelper.PageInterceptor">
  29. <!-- 使用下面的方式配置参数,后面会有所有的参数介绍 -->
  30. <!--<property name="param1" value="value1"/>-->
  31. <!-- 分页参数合理化 -->
  32. <property name="reasonable" value="true" />
  33. </plugin>
  34. </plugins>
  35.  
  36. </configuration>

mybatis-generator-config配置文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE generatorConfiguration
  3. PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  4. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  5.  
  6. <generatorConfiguration>
  7.  
  8. <!-- 引入配置文件 -->
  9. <properties resource="dbconfig.properties" />
  10.  
  11. <context id="DB2Tables" targetRuntime="MyBatis3">
  12.  
  13. <!--配置生成的增删改查方法不要注释-->
  14. <commentGenerator>
  15. <property name="suppressAllComments" value="true" />
  16. </commentGenerator>
  17.  
  18. <!--配置数据库链接信息-->
  19. <jdbcConnection driverClass="${jdbc.driverClass}"
  20. connectionURL="${jdbc.jdbcUrl}"
  21. userId="${jdbc.user}"
  22. password="${jdbc.password}">
  23. </jdbcConnection>
  24.  
  25. <javaTypeResolver >
  26. <property name="forceBigDecimals" value="false" />
  27. </javaTypeResolver>
  28.  
  29. <!--java模型生成,指定JavaBean生成的位置-->
  30. <javaModelGenerator targetPackage="club.iashe.pojo"
  31. targetProject=".\src\main\java">
  32. <property name="enableSubPackages" value="true" />
  33. <property name="trimStrings" value="true" />
  34. </javaModelGenerator>
  35.  
  36. <!--指定sql映射文件的位置-->
  37. <sqlMapGenerator targetPackage="mapper"
  38. targetProject=".\src\main\resources">
  39. <property name="enableSubPackages" value="true" />
  40. </sqlMapGenerator>
  41.  
  42. <!--指定DAO接口生成的位置-->
  43. <javaClientGenerator type="XMLMAPPER"
  44. targetPackage="club.iashe.dao"
  45. targetProject=".\src\main\java">
  46. <property name="enableSubPackages" value="true" />
  47. </javaClientGenerator>
  48.  
  49. <!--指定每个表的生成策略-->
  50. <!--<table tableName="resident_tag" domainObjectName="ResidentTag" />-->
  51. <table tableName="resident_info" domainObjectName="ResidentInfo" />
  52.  
  53. </context>
  54. </generatorConfiguration>

数据库配置文件dbconfig.properties

  1. jdbc.jdbcUrl=jdbc:mysql://localhost:3306/community?serverTimezone=UTC&zeroDateTimeBehavior=round
  2. jdbc.driverClass=com.mysql.cj.jdbc.Driver
  3. jdbc.user=root
  4. jdbc.password=

最后,web.xml的配置

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  5. version="3.1">
  6.  
  7. <!-- web.xml文件的配置 -->
  8.  
  9. <!-- 1.启动spring容器 -->
  10. <context-param>
  11. <param-name>contextConfigLocation</param-name>
  12. <!-- spring配置文件路径 -->
  13. <param-value>classpath:applicationContext.xml</param-value>
  14. </context-param>
  15. <!-- spring监听器 -->
  16. <listener>
  17. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  18. </listener>
  19.  
  20. <!-- 2、springMVC的前端控制器,拦截所有请求 -->
  21. <servlet>
  22. <!-- 配置springMVC的dispatcherServlet分发请求,实际上它是一个前端控制器 -->
  23. <servlet-name>dispatcherServlet</servlet-name>
  24. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  25. <load-on-startup>1</load-on-startup>
  26. </servlet>
  27. <servlet-mapping>
  28. <servlet-name>dispatcherServlet</servlet-name>
  29. <!--拦截所有页面请求-->
  30. <url-pattern>/</url-pattern>
  31. </servlet-mapping>
  32.  
  33. <!--3、字符编码过滤器,第一位的过滤器-->
  34. <filter>
  35. <filter-name>CharacterEncodingFilter</filter-name>
  36. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  37. <init-param>
  38. <param-name>encoding</param-name>
  39. <param-value>utf-8</param-value>
  40. </init-param>
  41. <init-param>
  42. <param-name>forceRequestEncoding</param-name>
  43. <param-value>true</param-value>
  44. </init-param>
  45. <init-param>
  46. <param-name>forceResponseEncoding</param-name>
  47. <param-value>true</param-value>
  48. </init-param>
  49. </filter>
  50. <filter-mapping>
  51. <filter-name>CharacterEncodingFilter</filter-name>
  52. <url-pattern>/*</url-pattern>
  53. </filter-mapping>
  54.  
  55. <!-- 4、使用rest风格的URI,将页面普通的post请求转为指定的delete或者put请求 -->
  56. <filter>
  57. <!-- hiddenHttpMethodFilter 可以把把post请求转船成 put delete -->
  58. <filter-name>HiddenHttpMethodFilter</filter-name>
  59. <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  60. </filter>
  61. <filter-mapping>
  62. <filter-name>HiddenHttpMethodFilter</filter-name>
  63. <url-pattern>/*</url-pattern>
  64. </filter-mapping>
  65. </web-app>

SSM+shiro,所有配置文件,详细注释版,自用的更多相关文章

  1. 经典剪枝算法的例题——Sticks详细注释版

    这题听说是道十分经典的剪枝算的题目,不要问我剪枝是什么,我也不知道,反正我只知道用到了深度搜索 我参考了好多资料才悟懂,然后我发现网上的那些大神原理讲的很明白,但代码没多少注释,看的很懵X,于是我抄起 ...

  2. SSM+shiro及相关插件的整合maven所有依赖,详细注释版,自用,持续更新

    整合了SSM+shiro框架,slf4j+logback日志,及一些好用的插件PageHelper,mybatis-generator,Lombok,fastjson等等 <?xml versi ...

  3. 一套强大的vim配置文件+详细注释

    phpchina折腾王独家配置,灰常牛叉的一套vim配置,另附有详细注释,自己折腾vim的时候可以参照其中的大部分设置进行一些个性化定制."是否兼容VI,compatible为兼容,noco ...

  4. SSM项目spring配置文件详细步骤(分门别类、灵巧记忆)

    spring-dao.xml文件 1.配置外部db.property文件: <context:property-placeholder location="classpath:jdbc ...

  5. DRF 简单使用(详细注释版)

    1.djangorestframework使用 下载安装 pip install djangorestframework ## djangorestframework pip install djan ...

  6. SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)【转】

    使用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没有记录SSM整合 ...

  7. SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)(转)

    使用 SSM ( Spring . SpringMVC 和 Mybatis )已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没 ...

  8. SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)

    使用 SSM ( Spring . SpringMVC 和 Mybatis )已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没 ...

  9. SSM三大框架整合详细教程

    使用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没有记录SSM整合 ...

随机推荐

  1. P1705 爱与愁过火(背包)

    本来是个搜索题,但是自觉的成了背包! 多重用正序,01用逆序. 抽象出来一下,一个物体的体积为ai, 每次装入背包需要bi(在题目中为菜数量)分钟(这个题目只是bi为 1 而已)问在r分钟内,装比n大 ...

  2. KazaQ's Socks (找规律)

    #include<iostream> using namespace std; #define ll long long ll n, m; ll t; int main(){ while ...

  3. Ubuntu 14.04 安装配置备忘录

    完全在 Linux 下工作,大概有3年时间了. 之前都是用 Windows, 而把 Linux 装在虚拟机里,现在反过来,把 Windows 装在了虚拟机里,只是因为偶尔还要用网银的缘故. 以我这几年 ...

  4. 接口测试,获取登录后的cookies

    参见: http://www.cnblogs.com/testwang/p/6023394.html

  5. Luogu P3703 [SDOI2017]树点涂色

    比较有趣的综合树上问题,刷LCT题单时做的但是发现后面LCT只是起了辅助作用233 首先我们分析每一个操作,\(1\)的定义就让我们联想到了access,我们回忆一下LCT的性质: LCT中每一个sp ...

  6. 图解SSH原理及两种登录方法

    SSH(Secure Shell)是一套协议标准,可以用来实现两台机器之间的安全登录以及安全的数据传送,其保证数据安全的原理是非对称加密. 传统的对称加密使用的是一套秘钥,数据的加密以及解密用的都是这 ...

  7. 微信小程序开发平台新功能「云开发」快速上手体验

    微信小程序开发平台刚刚开放了一个全新的功能:云开发. 简单地说就是将开发人员搭建微信小程序后端的成本再次降低,此文刚好在此产品公测时,来快速上手看看都有哪些方便开发者的功能更新. 微信小程序一直保持一 ...

  8. struts2之配置文件struts.xml详解

    struts配置文件 struts.xml配置参数详解 struts.xml中很大一部分配置默认配置就好了 但是有些还是需要做了解  以便于理解 和修改 <?xml version=" ...

  9. VMware威睿

    VMware总部位于美国加州帕洛阿尔托 [1]  ,是全球云基础架构和移动商务解决方案厂商,提供基于VMware的解决方案, 企业通过数据中心改造和公有云整合业务,借助企业安全转型维系客户信任 [2- ...

  10. 【学习总结】GirlsInAI ML-diary day-6-String字符串

    [学习总结]GirlsInAI ML-diary 总 原博github链接-day6 认识字符串 字符串的性质 字符串的玩法 1-字符串就是字符的序列 序列,代表字符串是有顺序的!这里很重要. 比如我 ...