ssM框架简单配置文件

来源:互联网 发布:wow7.0优化 编辑:程序博客网 时间:2024/05/19 20:37

1.web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee            http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"    version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">   <display-name>大众点评</display-name>   <welcome-file-list>      <welcome-file>index.jsp</welcome-file>   </welcome-file-list>   <filter>      <filter-name>CharacterEncodingFilter</filter-name>      <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>      <init-param>         <param-name>encoding</param-name>         <param-value>UTF-8</param-value>      </init-param>   </filter>   <filter-mapping>      <filter-name>CharacterEncodingFilter</filter-name>      <url-pattern>/*</url-pattern>   </filter-mapping>      <servlet>      <servlet-name>spring</servlet-name>      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>      <init-param>         <param-name>contextConfigLocation</param-name>         <param-value>classpath:spring/applicationContext.xml</param-value>      </init-param>      <load-on-startup>1</load-on-startup>   </servlet>   <servlet-mapping>      <servlet-name>spring</servlet-name>      <url-pattern>/</url-pattern>   </servlet-mapping>      <jsp-config>      <jsp-property-group>         <url-pattern>*.jsp</url-pattern>         <include-prelude>/WEB-INF/jsp/system/common.jsp</include-prelude>      </jsp-property-group>   </jsp-config></web-app>
2.applicationContext.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"       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-4.1.xsd">    <context:property-placeholder location="classpath:properties/*.properties"/>    <import resource="applicationContext-*.xml"/></beans>
3.applicationContext-dao.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"       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">    <!--数据库连接池-->    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">        <property name="driverClass" value="${driver}"/>        <property name="jdbcUrl" value="${url}"/>        <property name="user" value="${username}"/>        <property name="password" value="${password}"/>        <!--c3p0连接池私有属性-->        <property name="maxPoolSize" value="30"/>        <property name="minPoolSize" value="10"/>        <!--关闭连接后不自动提交-->        <property name="autoCommitOnClose" value="false"/>        <!--获取链接超时时间-->        <property name="checkoutTimeout" value="1000"/>        <!--当获取连接失败重试次数-->        <property name="acquireRetryAttempts" value="5"/>    </bean>    <!--配置sqlSessionFactory对象-->    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">        <!--注入数据库连接池-->        <property name="dataSource" ref="dataSource"/>        <!--配置mybatis全局配置文件:mybatis-config.xml-->        <property name="configLocation" value="classpath:mybatis-config.xml"/>        <!--扫描entity使用别名-->        <property name="typeAliasesPackage" value="org.imooc.bean"/>        <!--扫描sql配置文件:mapper需要的xml文件-->        <property name="mapperLocations" value="classpath:mapper/*.xml"/>    </bean>    <!--配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中-->    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">        <!--注入sqlSessionFactory-->        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>        <!--给出需要扫描的Dao接口-->        <property name="basePackage" value="org.imooc.dao"/>    </bean>    <!--自动扫描包名-->    <context:component-scan base-package="org.imooc.dao"/></beans>
4.applicationContext-service.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: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-4.1.xsd      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">    <!--扫描service包下所有类型-->    <context:component-scan base-package="org.imooc.service"/>    <!--配置事物管理器-->    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">        <!--注入数据库连接池-->        <property name="dataSource" ref="dataSource"/>    </bean>    <!--配置基于注解的声明式事务        默认使用注解来管理事务行为-->    <tx:annotation-driven transaction-manager="transactionManager"/></beans>
5.applicationContext-web.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:mvn="http://www.springframework.org/schema/cache"        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/cache http://www.springframework.org/schema/cache/spring-cache.xsd">    <!--开启注解-->    <mvc:annotation-driven/>    <!--允许对静态资源文件访问-->    <mvc:default-servlet-handler/>    <!--配置视图解析器-->    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>        <property name="prefix" value="/WEB-INF/jsp"></property>        <property name="suffix" value=".jsp"/>    </bean>    <!--配置文件上传解析器-->    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">        <!--指定所上传文件总大小不超过20M,注意maxUploadSize属性的限制不是针对单个文件-->        <property name="maxUploadSize" value="20000000"/>        <property name="defaultEncoding" value="utf-8"/>    </bean>    <!--自动扫描的包名-->    <context:component-scan base-package="org.imooc.controller"/></beans>
6.mybatis-config.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE configuration        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"        "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration>    <!--配置全局属性-->    <settings>        <!--使用jdbcgetGeneratedKeys,获取自增主键值-->        <setting name="useGeneratedKeys" value="true"/>        <!--使用列别名替换列名,默认true-->        <setting name="useColumnLabel" value="true"/>        <!--开启驼峰命名转换-->        <setting name="mapUnderscoreToCamelCase" value="true"/>    </settings></configuration>

原创粉丝点击