- springMVC.xml Configuration
Usually the main components springMVC.xml configuration view of the scanner and the resolver Controller
Example:
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 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 7 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 8 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 9 10 <!--启动注解识别--> 11 <context:annotation-config/> 12 13 <context:component-scan base-package="com.how2java.tmall.controller"> 14 <context:include-filter type="annotation" 15 expression="org.springframework.stereotype.Controller"/> 16 </context:component-scan> <1817 MVC: Annotation-Driven /> . 19 20 is <-! open access static resources -> 21 is < MVC: the servlet-default-Handler /> 22 is 23 is <-! View Positioning -> 24 < the bean 25 class = " org.springframework.web.servlet.view.InternalResourceViewResolver " > 26 is < Property name =" the viewClass " 27 value =" org.springframework.web.servlet.view.JstlView " /> 28 < Property name =" prefix " value ="/WEB-INF/jsp/" /> 29 <property name="suffix" value=".jsp" /> 30 </bean> 31 32 <!-- 对上传文件的解析--> 33 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> 34 </beans>
- applicationContext.xml arranged (for an increase in the web.xml file <listener>)
Example:
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:tx="http://www.springframework.org/schema/tx" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xsi:schemaLocation="http://www.springframework.org/schema/context 7 http://www.springframework.org/schema/context/spring-context-3.0.xsd 8 http://www.springframework.org/schema/beans 9 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 10 http://www.springframework.org/schema/tx . 11 http://www.springframework.org/schema/tx/ TX-3.0.xsd-Spring " > 12 is 13 is < context: Annotation-config /> 14 < context: Scan-Component Base-Package =" com.how2java.tmall.service " /> 15 16 ! <- import database configuration file -> . 17 < context: Property-placeholder LOCATION = "CLASSPATH: the jdbc.properties" /> 18 is <-! database connection pool configuration -> 19 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> 20 <!-- 基本属性 url、user、password --> 21 <property name="url" value="${jdbc.url}" /> 22 <property name="username" value="${jdbc.username}" /> 23 <property name="password" value="${jdbc.password}" /> 24 25 <!--Configuring the initial size, minimum, maximum -> 26 is < Property name = "initialSize" value = ". 1" /> 27 < Property name = "minIdle" value = ". 1" /> 28 < Property name = "for maxActive" value = "20" /> 29 30 <! - configuration acquiring connection waiting timeout -> 31 is < Property name = "maxWait" value = "60000" /> 32 33 is <!- intervals the frequency of such detection, an idle connection is detected to be closed, in milliseconds -> 34 <Property name = "timeBetweenEvictionRunsMillis" value = "60000" /> 35 36 <-! disposed a minimum connection time cell survival milliseconds -> 37 [ < Property name = "minEvictableIdleTimeMillis" value = "300000" / > 38 is 39 < Property name = "validationQuery" value = "the SELECT. 1" /> 40 < Property name = "testWhileIdle" value = "to true" /> 41 is <property name="testOnBorrow" value= "to false" /> 42 is < Property name = "testOnReturn" value = "to false" /> 43 is 44 is <-! open PSCache, and specifies the size of each connection PSCache -> 45 < Property name = "poolPreparedStatements" value = "to true" /> 46 is < Property name = "maxPoolPreparedStatementPerConnectionSize" 47 value = "20 is" /> 48 </ the bean > 49 50 <!- Mybatis of SessionFactory Configuration -> 51 <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean"> 52 <property name="typeAliasesPackage" value="com.how2java.tmall.pojo" /> 53 <property name="dataSource" ref="dataSource"/> 54 <property name="mapperLocations" value="classpath:mapper/*.xml"/> 55 <!-- 分页插件 --> 56 <property name="plugins"> 57 <array> 58 <bean class="com.github.pagehelper.PageInterceptor"> 59 <property name="properties"> 60 <value> 61 </value> 62 </property> 63 </bean> 64 </array> 65 </property> 66 </bean> 67 68 <!--Mybatis的Mapper文件识别--> 69 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 70 <property name="basePackage" value="com.how2java.tmall.mapper"/> 71 </bean> 72 73 <!--事务管理 --> 74 <tx:annotation-driven transaction-manager="transactionManager"/> 75 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 76 <property name="dataSource" ref="dataSource"/> 77 </bean> 78 79 </beans>
- web.xml file configuration
In the web.xml file, and will be introduced together springMVC.xml applicationContext.xml
Example:
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_2_5.xsd" 5 version="2.5"> 6 7 <!-- spring的配置文件--> 8 <context-param> 9 <param-name>contextConfigLocation</param-name> 10 <param-value>classpath:applicationContext.xml</param-value> 11 </context-param> 12 <listener> 13 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 14 </listener> 15 16 <!--中文字符编码过滤器--> 17 <filter> 18 <filter-name>CharacterEncodingFilter</filter-name> 19 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 20 <init-param> 21 <param-name>encoding</param-name> 22 <param-value>utf-8</param-value> 23 </init-param> 24 </filter> 25 <filter-mapping> 26 <filter-name>CharacterEncodingFilter</filter-name> 27 <url-pattern>/*</url-pattern> 28 </filter-mapping> 29 30 <!-- spring mvc核心:分发servlet --> 31 <servlet> 32 <servlet-name>mvc-dispatcher</servlet-name> 33 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 34 <!-- spring mvc的配置文件 --> 35 <init-param> 36 <param-name>contextConfigLocation</param-name> 37 <param-value>classpath:springMVC.xml</param-value> 38 </init-param> 39 <load-on-startup>1</load-on-startup> 40 </servlet> 41 <servlet-mapping> 42 <servlet-name>mvc-dispatcher</servlet-name> 43 <url-pattern>/</url-pattern> 44 </servlet-mapping> 45 46 </web-app>
Written on Oct. 14th, 2019