Spring+SpringMVC+Mybatics配置文件解析

Spring-config.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:aop="http://www.springframework.org/schema/aop"       xmlns:tx="http://www.springframework.org/schema/tx"       xmlns:p="http://www.springframework.org/schema/p"       xmlns:context="http://www.springframework.org/schema/context"       xmlns:cache="http://www.springframework.org/schema/cache"       xmlns:mvc="http://www.springframework.org/schema/mvc"       xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd		http://www.springframework.org/schema/cache		http://www.springframework.org/schema/cache/spring-cache.xsd		http://www.springframework.org/schema/tx         http://www.springframework.org/schema/tx/spring-tx.xsd ">    <!-- 配置数据源 -->    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">        <property name="driverClass" value="com.mysql.jdbc.Driver"/>        <property name="jdbcUrl"                  value="jdbc:mysql://localhost:3306/pea"/>        <property name="user" value="root"/>        <property name="password" value="123456"/>        <property name="minPoolSize" value="5"/>        <property name="maxPoolSize" value="20"/>    </bean>    <!-- 配置SqlSessionFactoryBean -->    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="dataSource" ref="dataSource"/>    </bean>     <bean id="UserMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">  		<property name="mapperInterface" value="weixin.pea.pojo.UserMapper" />  		<property name="sqlSessionFactory" ref="sqlSessionFactory" />	</bean>    <!-- 配置DataSourceTransactionManager(事务管理) -->    <bean id="transactionManager"          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">        <property name="dataSource" ref="dataSource"/>    </bean>    	<!--验证器-->    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">        <!--注入hibernate的验证器-->        <property name="providerClass"  value="org.hibernate.validator.HibernateValidator"/>	</bean>   <!-- 配置multipart解析器 -->  <bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver" />    <!-- 使用声明式事务管理方式 -->    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> </beans>复制代码

SpringMVC-servlet.xml

<?xml version="1.0" encoding="UTF-8"?><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:jdbc="http://www.springframework.org/schema/jdbc"	xmlns:jee="http://www.springframework.org/schema/jee"	xmlns:aop="http://www.springframework.org/schema/aop"	xmlns:tx="http://www.springframework.org/schema/tx"	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/mvc	http://www.springframework.org/schema/mvc/spring-mvc.xsd	http://www.springframework.org/schema/tx	http://www.springframework.org/schema/tx/spring-tx.xsd	http://www.springframework.org/schema/aop	http://www.springframework.org/schema/aop/spring-aop.xsd">     <!-- 配置视图解析器 -->     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">         <!-- 使用前缀和后缀 -->         <property name="prefix" value=""></property>         <property name="suffix" value=".jsp"></property>     </bean>     <!-- 使用注解驱动,不用注解驱动,component-scan则无效,bean也无法装配 -->     <!-- 使用注解驱动,会自动注册处理器适配器 -->     <mvc:annotation-driven></mvc:annotation-driven>    <!-- 设置使用注解的类所在的包 -->   <context:component-scan base-package="weixin.pea.*" >   </context:component-scan>     <!-- 配置注解的处理器映射器和处理器适配器 -->      <!-- 访问静态资源文件处理器,<mvc:default-servlet-handler/>,没配置这个就访问不了图片,css,js等静态资源-->	<mvc:default-servlet-handler/><!--     	配置拦截器	<mvc:interceptors>	<mvc:interceptor>	<mvc:mapping path="*.do" />	<bean class=""></bean>	</mvc:interceptor>    </mvc:interceptors>     --> </beans>复制代码

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>weixin.pea</display-name>	<context-param>		<param-name>contextConfigLocation</param-name>		<param-value>classpath:spring-config.xml</param-value>	</context-param>	<listener>		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>	</listener>	<filter>        <filter-name>encodingFilter</filter-name>        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>        <async-supported>true</async-supported>        <init-param>        <param-name>encoding</param-name>        <param-value>UTF-8</param-value>        </init-param>    </filter>    <filter-mapping>       <filter-name>encodingFilter</filter-name>       <url-pattern>/*</url-pattern>    </filter-mapping>	<servlet>		<servlet-name>SpringMVC</servlet-name>		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>		<init-param>			<param-name>contextConfigLocation</param-name>			<param-value>classpath:SpringMVC-servlet.xml</param-value>		</init-param>		<load-on-startup>1</load-on-startup>		<multipart-config>			<location>/Users/pengchunkao/eclipse-workspace/pea/src/main/webapp/image/</location>			<max-file-size>2097152600</max-file-size>			<max-request-size>4194304600</max-request-size>		</multipart-config>	</servlet>	<servlet-mapping>    		<servlet-name>SpringMVC</servlet-name>    <!--        一般有以下写法:        *.do    拦截固定格式的请求        /       rest风格的写法:拦截所有资源,需要针对静态资源做单独处理        /*      错误写法:会在处理完请求后拦截jsp导致404错误     -->    		<url-pattern>/</url-pattern>	</servlet-mapping>	<!-- 添加这个servlet --></web-app>

复制代码


转载于:https://juejin.im/post/5cde6ae751882525b40cc890

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值