一个完整的ssm项目环境配置

http://blog.csdn.net/yubu_/article/details/75058962

本文使用maven来构建ssm项目,至于开始如何使用eclipse搭建web项目就不介绍了,主要介绍最麻烦的框架配置内容。

1.项目结构如下图

一个完整的ssm项目环境配置_第1张图片一个完整的ssm项目环境配置_第2张图片

2.pom.xml文件

[html] view plain copy
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.       
  4.     <modelVersion>4.0.0modelVersion>  
  5.     <groupId>DemogroupId>  
  6.     <artifactId>buoumallartifactId>  
  7.     <packaging>warpackaging>  
  8.     <version>0.0.1-SNAPSHOTversion>  
  9.     <name>buoumall Maven Webappname>  
  10.     <url>http://maven.apache.orgurl>  
  11.   
  12.   
  13.     <properties>  
  14.           
  15.         <spring.version>4.3.0.RELEASEspring.version>  
  16.           
  17.         <mybatis.version>3.2.6mybatis.version>  
  18.           
  19.         <slf4j.version>1.7.7slf4j.version>  
  20.         <log4j.version>1.2.17log4j.version>  
  21.         <dubbo.version>2.8.4dubbo.version>  
  22.         <aspectj.version>1.7.3aspectj.version>  
  23.         <httpcomponents.version>4.4.1httpcomponents.version>  
  24.     properties>  
  25.   
  26.     <dependencies>  
  27.   
  28.           
  29.         <dependency>  
  30.             <groupId>org.apache.velocitygroupId>  
  31.             <artifactId>velocityartifactId>  
  32.             <version>1.7version>  
  33.         dependency>  
  34.   
  35.           
  36.         <dependency>  
  37.             <groupId>com.baomidougroupId>  
  38.             <artifactId>mybatis-plusartifactId>  
  39.             <version>2.0.2version>  
  40.         dependency>  
  41.   
  42.         <dependency>  
  43.             <groupId>org.mybatis.generatorgroupId>  
  44.             <artifactId>mybatis-generator-coreartifactId>  
  45.             <version>1.3.2version>  
  46.         dependency>  
  47.           
  48.   
  49.           
  50.         <dependency>  
  51.             <groupId>junitgroupId>  
  52.             <artifactId>junitartifactId>  
  53.             <version>4.11version>  
  54.             <scope>testscope>  
  55.         dependency>  
  56.   
  57.         <dependency>  
  58.             <groupId>javax.servletgroupId>  
  59.             <artifactId>javax.servlet-apiartifactId>  
  60.             <version>3.0.1version>  
  61.               
  62.             <scope>providedscope>  
  63.         dependency>  
  64.   
  65.           
  66.         <dependency>  
  67.             <groupId>org.springframeworkgroupId>  
  68.             <artifactId>spring-coreartifactId>  
  69.             <version>${spring.version}version>  
  70.         dependency>  
  71.   
  72.         <dependency>  
  73.             <groupId>org.springframeworkgroupId>  
  74.             <artifactId>spring-webartifactId>  
  75.             <version>${spring.version}version>  
  76.         dependency>  
  77.   
  78.         <dependency>  
  79.             <groupId>org.springframeworkgroupId>  
  80.             <artifactId>spring-oxmartifactId>  
  81.             <version>${spring.version}version>  
  82.         dependency>  
  83.   
  84.         <dependency>  
  85.             <groupId>org.springframeworkgroupId>  
  86.             <artifactId>spring-txartifactId>  
  87.             <version>${spring.version}version>  
  88.         dependency>  
  89.   
  90.         <dependency>  
  91.             <groupId>org.springframeworkgroupId>  
  92.             <artifactId>spring-jdbcartifactId>  
  93.             <version>${spring.version}version>  
  94.         dependency>  
  95.   
  96.         <dependency>  
  97.             <groupId>org.springframeworkgroupId>  
  98.             <artifactId>spring-webmvcartifactId>  
  99.             <version>${spring.version}version>  
  100.         dependency>  
  101.   
  102.         <dependency>  
  103.             <groupId>org.springframeworkgroupId>  
  104.             <artifactId>spring-aopartifactId>  
  105.             <version>${spring.version}version>  
  106.         dependency>  
  107.   
  108.         <dependency>  
  109.             <groupId>org.springframeworkgroupId>  
  110.             <artifactId>spring-context-supportartifactId>  
  111.             <version>${spring.version}version>  
  112.         dependency>  
  113.   
  114.         <dependency>  
  115.             <groupId>org.springframeworkgroupId>  
  116.             <artifactId>spring-testartifactId>  
  117.             <version>${spring.version}version>  
  118.         dependency>  
  119.           
  120.   
  121.           
  122.         <dependency>  
  123.             <groupId>org.aspectjgroupId>  
  124.             <artifactId>aspectjweaverartifactId>  
  125.             <version>${aspectj.version}version>  
  126.         dependency>  
  127.         <dependency>  
  128.             <groupId>org.aspectjgroupId>  
  129.             <artifactId>aspectjrtartifactId>  
  130.             <version>${aspectj.version}version>  
  131.         dependency>  
  132.           
  133.   
  134.           
  135.         <dependency>  
  136.             <groupId>org.mybatisgroupId>  
  137.             <artifactId>mybatisartifactId>  
  138.             <version>${mybatis.version}version>  
  139.         dependency>  
  140.   
  141.           
  142.         <dependency>  
  143.             <groupId>org.mybatisgroupId>  
  144.             <artifactId>mybatis-springartifactId>  
  145.             <version>1.2.2version>  
  146.         dependency>  
  147.   
  148.           
  149.         <dependency>  
  150.             <groupId>org.hibernategroupId>  
  151.             <artifactId>hibernate-validatorartifactId>  
  152.             <version>5.3.4.Finalversion>  
  153.         dependency>  
  154.   
  155.           
  156.         <dependency>  
  157.             <groupId>javaxgroupId>  
  158.             <artifactId>javaee-apiartifactId>  
  159.             <version>7.0version>  
  160.         dependency>  
  161.   
  162.           
  163.         <dependency>  
  164.             <groupId>mysqlgroupId>  
  165.             <artifactId>mysql-connector-javaartifactId>  
  166.             <version>5.1.30version>  
  167.         dependency>  
  168.   
  169.           
  170.         <dependency>  
  171.             <groupId>jstlgroupId>  
  172.             <artifactId>jstlartifactId>  
  173.             <version>1.2version>  
  174.         dependency>  
  175.   
  176.           
  177.           
  178.         <dependency>  
  179.             <groupId>log4jgroupId>  
  180.             <artifactId>log4jartifactId>  
  181.             <version>${log4j.version}version>  
  182.         dependency>  
  183.   
  184.           
  185.         <dependency>  
  186.             <groupId>com.alibabagroupId>  
  187.             <artifactId>fastjsonartifactId>  
  188.             <version>1.2.17version>  
  189.         dependency>  
  190.   
  191.         <dependency>  
  192.             <groupId>org.slf4jgroupId>  
  193.             <artifactId>slf4j-apiartifactId>  
  194.             <version>${slf4j.version}version>  
  195.         dependency>  
  196.   
  197.         <dependency>  
  198.             <groupId>org.slf4jgroupId>  
  199.             <artifactId>slf4j-log4j12artifactId>  
  200.             <version>${slf4j.version}version>  
  201.         dependency>  
  202.           
  203.   
  204.           
  205.         <dependency>  
  206.             <groupId>com.github.pagehelpergroupId>  
  207.             <artifactId>pagehelperartifactId>  
  208.             <version>4.2.0version>  
  209.         dependency>  
  210.   
  211.           
  212.         <dependency>  
  213.             <groupId>com.belerwebgroupId>  
  214.             <artifactId>pinyin4jartifactId>  
  215.             <version>2.5.0version>  
  216.         dependency>  
  217.   
  218.           
  219.         <dependency>  
  220.             <groupId>org.freemarkergroupId>  
  221.             <artifactId>freemarkerartifactId>  
  222.             <version>2.3.23version>  
  223.         dependency>  
  224.   
  225.           
  226.         <dependency>  
  227.             <groupId>com.alibabagroupId>  
  228.             <artifactId>druidartifactId>  
  229.             <version>1.0.26version>  
  230.         dependency>  
  231.   
  232.           
  233.         <dependency>  
  234.             <groupId>com.alibabagroupId>  
  235.             <artifactId>dubboartifactId>  
  236.             <version>${dubbo.version}version>  
  237.         dependency>  
  238.   
  239.           
  240.         <dependency>  
  241.             <groupId>com.google.guavagroupId>  
  242.             <artifactId>guavaartifactId>  
  243.             <version>18.0version>  
  244.         dependency>  
  245.   
  246.           
  247.         <dependency>  
  248.             <groupId>org.codehaus.jacksongroupId>  
  249.             <artifactId>jackson-mapper-aslartifactId>  
  250.             <version>1.9.13version>  
  251.         dependency>  
  252.   
  253.           
  254.         <dependency>  
  255.             <groupId>org.apache.commonsgroupId>  
  256.             <artifactId>commons-lang3artifactId>  
  257.             <version>3.3.2version>  
  258.         dependency>  
  259.   
  260.         <dependency>  
  261.             <groupId>commons-collectionsgroupId>  
  262.             <artifactId>commons-collectionsartifactId>  
  263.             <version>3.2.1version>  
  264.         dependency>  
  265.   
  266.         <dependency>  
  267.             <groupId>commons-beanutilsgroupId>  
  268.             <artifactId>commons-beanutilsartifactId>  
  269.             <version>1.9.2version>  
  270.             <exclusions>  
  271.                 <exclusion>  
  272.                     <artifactId>commons-loggingartifactId>  
  273.                     <groupId>commons-logginggroupId>  
  274.                 exclusion>  
  275.             exclusions>  
  276.         dependency>  
  277.   
  278.         <dependency>  
  279.             <groupId>commons-iogroupId>  
  280.             <artifactId>commons-ioartifactId>  
  281.             <version>2.4version>  
  282.         dependency>  
  283.   
  284.         <dependency>  
  285.             <groupId>commons-codecgroupId>  
  286.             <artifactId>commons-codecartifactId>  
  287.             <version>1.9version>  
  288.         dependency>  
  289.   
  290.         <dependency>  
  291.             <groupId>org.apache.httpcomponentsgroupId>  
  292.             <artifactId>httpclientartifactId>  
  293.             <version>${httpcomponents.version}version>  
  294.         dependency>  
  295.   
  296.         <dependency>  
  297.             <groupId>org.apache.httpcomponentsgroupId>  
  298.             <artifactId>httpcoreartifactId>  
  299.             <version>${httpcomponents.version}version>  
  300.         dependency>  
  301.   
  302.         <dependency>  
  303.             <groupId>org.apache.httpcomponentsgroupId>  
  304.             <artifactId>httpmimeartifactId>  
  305.             <version>${httpcomponents.version}version>  
  306.         dependency>  
  307.   
  308.         <dependency>  
  309.             <groupId>org.apache.httpcomponentsgroupId>  
  310.             <artifactId>httpclient-cacheartifactId>  
  311.             <version>${httpcomponents.version}version>  
  312.         dependency>  
  313.           
  314.   
  315.           
  316.         <dependency>  
  317.             <groupId>commons-fileuploadgroupId>  
  318.             <artifactId>commons-fileuploadartifactId>  
  319.             <version>1.3.1version>  
  320.         dependency>  
  321.   
  322.           
  323.         <dependency>  
  324.             <groupId>com.googlecode.log4jdbcgroupId>  
  325.             <artifactId>log4jdbcartifactId>  
  326.             <version>1.2version>  
  327.             <scope>runtimescope>  
  328.         dependency>  
  329.   
  330.     dependencies>  
  331.   
  332.     <build>  
  333.         <finalName>buoumallfinalName>  
  334.         <plugins>  
  335.             <plugin>  
  336.                 <groupId>org.apache.maven.pluginsgroupId>  
  337.                 <artifactId>maven-compiler-pluginartifactId>  
  338.                 <configuration>  
  339.                     <source>1.8source>  
  340.                     <target>1.8target>  
  341.                 configuration>  
  342.             plugin>  
  343.         plugins>  
  344.         <resources>  
  345.             <resource>  
  346.                 <directory>src/main/resourcesdirectory>  
  347.                 <filtering>falsefiltering>  
  348.             resource>  
  349.             <resource>  
  350.                 <directory>src/main/conf/devdirectory>  
  351.                 <filtering>falsefiltering>  
  352.             resource>  
  353.         resources>  
  354.     build>  
  355.   
  356. project>  
3.web.xml的配置
[html] view plain copy
  1. xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xmlns="http://java.sun.com/xml/ns/javaee"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  
  5.     id="WebApp_ID" version="3.0">  
  6.       
  7.     <display-name>buoumall-businessdisplay-name>  
  8.   
  9.        
  10.     <context-param>  
  11.         <param-name>contextConfigLocationparam-name>  
  12.         <param-value>  
  13.             classpath:spring/applicationContext.xml  
  14.         param-value>  
  15.     context-param>  
  16.       
  17.        
  18.     <listener>  
  19.         <listener-class>  
  20.             org.springframework.web.util.Log4jConfigListener  
  21.         listener-class>  
  22.     listener>  
  23.       
  24.       
  25.     <listener>  
  26.         <listener-class>  
  27.             org.springframework.web.context.ContextLoaderListener  
  28.         listener-class>  
  29.     listener>  
  30.       
  31.          
  32.         <filter>     
  33.             <filter-name>encodingFilterfilter-name>     
  34.             <filter-class>     
  35.                 org.springframework.web.filter.CharacterEncodingFilter     
  36.             filter-class>     
  37.             <init-param>     
  38.                 <param-name>encodingparam-name>     
  39.                 <param-value>UTF-8param-value>     
  40.             init-param>     
  41.         filter>     
  42.         <filter-mapping>     
  43.             <filter-name>encodingFilterfilter-name>     
  44.             <url-pattern>/*url-pattern>     
  45.         filter-mapping>   
  46.       
  47.           
  48.         <servlet>  
  49.         <servlet-name>springMvcservlet-name>  
  50.         <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>  
  51.         <init-param>  
  52.             <param-name>contextConfigLocationparam-name>  
  53.             <param-value>classpath:spring/spring-mvc-servlet.xmlparam-value>  
  54.         init-param>  
  55.         <load-on-startup>1load-on-startup>  
  56.     servlet>  
  57.     <servlet-mapping>  
  58.         <servlet-name>springMvcservlet-name>  
  59.         <url-pattern>/url-pattern>  
  60.     servlet-mapping>   
  61.       
  62.       
  63.     <session-config>  
  64.         <session-timeout>480session-timeout>  
  65.     session-config>  
  66.   
  67. web-app>  
4.在mybatis文件下建立mybatis-config.xml文件
[html] view plain copy
  1. xml version="1.0" encoding="UTF-8"?>  
  2.     "http://mybatis.org/dtd/mybatis-3-config.dtd">  
  3. <configuration>  
  4.     <settings>  
  5.           
  6.         <setting name="cacheEnabled" value="true" />  
  7.           
  8.           
  9.         <setting name="lazyLoadingEnabled" value="true" />  
  10.           
  11.           
  12.         <setting name="aggressiveLazyLoading" value="true" />  
  13.           
  14.           
  15.         <setting name="multipleResultSetsEnabled" value="true" />  
  16.           
  17.           
  18.         <setting name="useColumnLabel" value="true" />  
  19.           
  20.           
  21.         <setting name="defaultStatementTimeout" value="25000" />  
  22.           
  23.     settings>  
  24. configuration>  
4.spring和mybatis的整合文件spring-bean-mybatis.xml
[html] view plain copy
  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:jdbc="http://www.springframework.org/schema/jdbc"   
  6.     xmlns:jee="http://www.springframework.org/schema/jee"  
  7.     xmlns:tx="http://www.springframework.org/schema/tx"   
  8.     xmlns:util="http://www.springframework.org/schema/util"  
  9.     xmlns:task="http://www.springframework.org/schema/task"   
  10.     xmlns:aop="http://www.springframework.org/schema/aop"  
  11.     xsi:schemaLocation="  
  12.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
  13.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
  14.         http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd  
  15.         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
  16.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd  
  17.         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd  
  18.         http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd  
  19.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">  
  20.       
  21.                          
  22.     <context:property-placeholder location="classpath:mysql.properties" ignore-unresolvable="true" />  
  23.       
  24.       
  25.       
  26.       
  27.     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">  
  28.            
  29.          <property name="url" value="${jdbc.url}" />    
  30.          <property name="username" value="${jdbc.username}" />    
  31.          <property name="password" value="${jdbc.password}" />    
  32.          <property name="driverClassName" value="${jdbc.driverClassName}" />    
  33.          <property name="filters" value="${jdbc.filters}" />    
  34.            
  35.          <property name="maxActive" value="${jdbc.maxActive}" />  
  36.            
  37.          <property name="initialSize" value="${jdbc.initialSize}" />  
  38.            
  39.          <property name="maxWait" value="${jdbc.maxWait}" />  
  40.            
  41.          <property name="minIdle" value="${jdbc.minIdle}" />    
  42.            
  43.          <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />  
  44.            
  45.          <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />    
  46.          <property name="validationQuery" value="${jdbc.validationQuery}" />    
  47.          <property name="testWhileIdle" value="${jdbc.testWhileIdle}" />    
  48.          <property name="testOnBorrow" value="${jdbc.testOnBorrow}" />    
  49.          <property name="testOnReturn" value="${jdbc.testOnReturn}" />    
  50.          <property name="maxOpenPreparedStatements" value="${jdbc.maxOpenPreparedStatements}" />  
  51.            
  52.          <property name="removeAbandoned" value="${jdbc.removeAbandoned}" />  
  53.            
  54.          <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />  
  55.               
  56.          <property name="logAbandoned" value="${jdbc.logAbandoned}" />  
  57.     bean>   
  58.       
  59.     <bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">     
  60.         <property name="dataSource" ref="dataSource" />  
  61.     bean>  
  62.       
  63.           
  64.           
  65.     <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />  
  66.       
  67.       
  68.       
  69.     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
  70.             <property name="dataSource" ref="dataSource" />  
  71.             <property name="configLocation" value="classpath:mybatis/mybatis-config.xml" />  
  72.               
  73.             <property name="mapperLocations" value="classpath:mybatis/*Dao.xml" />  
  74.             <property name="typeAliasesPackage" value="com.buoumall.business.entity"/>  
  75.             <property name="plugins">  
  76.                 <array>  
  77.                     <bean class="com.github.pagehelper.PageHelper">  
  78.                           
  79.                         <property name="properties">  
  80.                             <value>  
  81.                                 dialect=mysql  
  82.                                 offsetAsPageNum=true  
  83.                                 rowBoundsWithCount=true  
  84.                                 reasonable=true  
  85.                                 supportMethodsArguments=true  
  86.                                 params=count=countSql  
  87.                                 autoRuntimeDialect=true  
  88.                             value>  
  89.                         property>  
  90.                     bean>  
  91.                 array>  
  92.             property>  
  93.         bean>  
  94.       
  95. <span style="white-space:pre">  span>  
  96.     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
  97.         <property name="annotationClass" value="org.springframework.stereotype.Repository" />  
  98.         <property name="basePackage" value="com.buoumall.business.dao" />  
  99.     bean>  
  100.       
  101. <span style="white-space:pre">  span>   
  102. <span style="white-space:pre">  span><bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">  
  103.         <constructor-arg ref="sqlSessionFactory" />  
  104.     bean>  
  105.       
  106.     <context:property-placeholder location="classpath:redis.properties" ignore-unresolvable="true" />  
  107.       
  108.     <bean class="com.buoumall.commonService.config.RedisConfiguration">  
  109.        <property name="maxIdle" value="${redis.maxIdle}" />  
  110.        <property name="maxTotal" value="${redis.maxTotal}" />  
  111.        <property name="maxWaitMillis" value="${redis.maxWaitMillis}" />  
  112.        <property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}" />  
  113.        <property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}" />  
  114.        <property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}" />  
  115.        <property name="hostName" value="${redis.hostName}" />  
  116.        <property name="port" value="${redis.port}" />  
  117.        <property name="password" value="${redis.password}" />  
  118.        <property name="database" value="${redis.database}" />  
  119.        <property name="redisNamespace" value="${redis.redisNamespace}" />  
  120.     bean>  
  121.       
  122.     <context:property-placeholder location="classpath:oss.properties" ignore-unresolvable="true" />  
  123.       
  124.     <bean class="com.buoumall.commonService.config.OssConfiguration">  
  125.        <property name="endpoint" value="${oss.endpoint}" />  
  126.        <property name="accessKeyId" value="${oss.accessKeyId}" />  
  127.        <property name="accessKeySecret" value="${oss.accessKeySecret}" />  
  128.        <property name="bucketName" value="${oss.bucketName}" />  
  129.        <property name="imgDomain" value="${oss.imgDomain}" />  
  130.     bean>  
  131.       
  132.       
  133.         <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>  
  134.         <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>  
  135.     context:component-scan>  
  136.       
  137. beans>  
5.spring的配置文件applicationContext.xml
[html] view plain copy
  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:dubbo="http://code.alibabatech.com/schema/dubbo"  
  6.        xsi:schemaLocation="  
  7.         http://www.springframework.org/schema/beans   
  8.         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
  9.         http://www.springframework.org/schema/context   
  10.         http://www.springframework.org/schema/context/spring-context-4.0.xsd  
  11.         http://code.alibabatech.com/schema/dubbo  
  12.         http://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
  13.           
  14.     <import resource="classpath:spring/spring-bean-mybaits.xml" />  
  15. beans>  
6.spring MVC的配置文件spring-mvc-servlet.xml
[html] view plain copy
  1. xml version="1.0" encoding="UTF-8"?>  
  2. <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:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans  
  3.     http://www.springframework.org/schema/beans/spring-beans.xsd  
  4.     http://www.springframework.org/schema/context  
  5.     http://www.springframework.org/schema/context/spring-context.xsd  
  6.     http://www.springframework.org/schema/mvc  
  7.     http://www.springframework.org/schema/mvc/spring-mvc.xsd  
  8.     http://www.springframework.org/schema/util  
  9.     http://www.springframework.org/schema/util/spring-util.xsd">  
  10.   
  11.     <util:properties id="configProperties" location="classpath:init.properties" />  
  12.       
  13.     <context:property-placeholder properties-ref="configProperties" />  
  14.   
  15.     <bean id="propertyConfigurer" class="com.buoumall.business.util.Configurer">  
  16.         <property name="properties" ref="configProperties" />  
  17.     bean>  
  18.   
  19.       
  20.       
  21.     <context:component-scan base-package="com.buoumall.business.controller" use-default-filters="false">  
  22.         <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />  
  23.         <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />  
  24.     context:component-scan>  
  25.     <mvc:annotation-driven>  
  26.         <mvc:message-converters>  
  27.             <bean class="org.springframework.http.converter.StringHttpMessageConverter">  
  28.                 <property name="supportedMediaTypes">  
  29.                     <list>  
  30.                         <value>text/plain;charset=UTF-8value>  
  31.                         <value>text/html;charset=UTF-8value>  
  32.                     list>  
  33.                 property>  
  34.             bean>  
  35.               
  36.             <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">    
  37.                 <property name="supportedMediaTypes">   
  38.                     <list>    
  39.                         <value>application/json;charset=UTF-8value>    
  40.                     list>    
  41.                 property>  
  42.                 <property name="features">  
  43.                     <list>  
  44.                         <value>DisableCircularReferenceDetectvalue>  
  45.                         <value>WriteMapNullValuevalue>  
  46.                         <value>WriteNullListAsEmptyvalue>  
  47.                         <value>WriteNullStringAsEmptyvalue>  
  48.                         <value>WriteNullNumberAsZerovalue>  
  49.                         <value>WriteNullBooleanAsFalsevalue>  
  50.                         <value>WriteNonStringKeyAsStringvalue>  
  51.                         <value>BrowserCompatiblevalue>  
  52.                     list>  
  53.                 property>    
  54.             bean>  
  55.         mvc:message-converters>  
  56.     mvc:annotation-driven>  
  57.   
  58.       
  59.     <mvc:status-controller path="/status" status-code="200" />  
  60.       
  61.     <mvc:resources mapping="/static/**" location="/static/" />  
  62.     <mvc:resources mapping="/favicon.ico" location="/favicon.ico"/>  
  63.   
  64.       
  65.     <mvc:interceptors>  
  66.           
  67.         <mvc:interceptor>  
  68.           <mvc:mapping path="/**"/>  
  69.           <mvc:exclude-mapping path="/status"/>  
  70.           <mvc:exclude-mapping path="/static/**"/>  
  71.           <mvc:exclude-mapping path="/favicon.ico"/>  
  72.           <bean class="com.buoumall.business.interceptor.GlobalInterceptor" />  
  73.         mvc:interceptor>  
  74.           
  75.         <mvc:interceptor>  
  76.           <mvc:mapping path="/**"/>  
  77.           <mvc:exclude-mapping path="/status"/>  
  78.           <mvc:exclude-mapping path="/static/**"/>  
  79.           <mvc:exclude-mapping path="/favicon.ico"/>  
  80.           <bean class="com.buoumall.business.interceptor.LoginInterceptor" />  
  81.         mvc:interceptor>  
  82.     mvc:interceptors>  
  83.   
  84.     <mvc:view-controller path="/" view-name="redirect:/login" />  
  85.   
  86.       
  87.       
  88.     <bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">  
  89.         <property name="templateLoaderPath" value="/WEB-INF/template/" />  
  90.         <property name="freemarkerSettings">  
  91.             <props>  
  92.                 <prop key="template_update_delay">0prop>  
  93.                 <prop key="defaultEncoding">UTF-8prop>  
  94.                 <prop key="url_escaping_charset">UTF-8prop>  
  95.                 <prop key="locale">zh_CNprop>  
  96.                 <prop key="boolean_format">true,falseprop>  
  97.                 <prop key="date_format">yyyy-MM-ddprop>  
  98.                 <prop key="time_format">HH:mm:ssprop>  
  99.                 <prop key="datetime_format">yyyy-MM-dd HH:mm:ssprop>  
  100.                 <prop key="number_format">#.##prop>  
  101.                 <prop key="whitespace_stripping">trueprop>  
  102.                 <prop key="classic_compatible">trueprop>  
  103.                 <prop key="template_exception_handler">ignoreprop>  
  104.             props>  
  105.         property>  
  106.     bean>  
  107.   
  108.       
  109.     <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">  
  110.         <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />  
  111.         <property name="cache" value="true" />  
  112.         <property name="order" value="0" />  
  113.         <property name="prefix" value="" />  
  114.         <property name="suffix" value=".html" />  
  115.         <property name="contentType" value="text/html;charset=UTF-8" />  
  116.         <property name="requestContextAttribute" value="request" />  
  117.         <property name="exposeSpringMacroHelpers" value="true" />  
  118.         <property name="exposeRequestAttributes" value="true" />  
  119.         <property name="exposeSessionAttributes" value="true" />  
  120.     bean>  
  121.   
  122.       
  123.     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
  124.         <property name="maxUploadSize">  
  125.             <value>104857600value>  
  126.         property>  
  127.         <property name="maxInMemorySize">  
  128.             <value>4096value>  
  129.         property>  
  130.         <property name="defaultEncoding">  
  131.             <value>utf-8value>  
  132.         property>  
  133.     bean>  
  134.   
  135. beans> 

你可能感兴趣的:(java教程)