SSM三大框架整合配置(Spring+SpringMVC+MyBatis)

web.xml

xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         id="WebApp_ID" version="3.1">
  
  <servlet>
    <servlet-name>UserManageservlet-name>
    <servlet-class>
      org.springframework.web.servlet.DispatcherServlet
    servlet-class>
    <init-param>
      <param-name>contextConfigLocationparam-name>
      <param-value>/WEB-INF/config/UserManage-servlet.xmlparam-value>
    init-param>
    <load-on-startup>1load-on-startup>
  servlet>

  
  <servlet-mapping>
    <servlet-name>UserManageservlet-name>
    <url-pattern>/url-pattern>
  servlet-mapping>

  
  
  <context-param>
    <param-name>contextConfigLocationparam-name>
    <param-value>WEB-INF/config/spring-config.xmlparam-value>
    
  context-param>

  
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
  listener>
  

  
  <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListenerlistener-class>
  listener>

  
  <welcome-file-list>
    <welcome-file>index.jspwelcome-file>
  welcome-file-list>

  
  <session-config>
    <session-timeout>10session-timeout>
  session-config>


  
  <filter>
    <filter-name>CharacterEncodingfilter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
    <init-param>
      <param-name>encodingparam-name>
      <param-value>UTF-8param-value>
    init-param>
    <init-param>
      <param-name>forceEncodingparam-name>
      <param-value>trueparam-value>
    init-param>
  filter>
  <filter-mapping>
    <filter-name>CharacterEncodingfilter-name>
    <url-pattern>/*url-pattern>
  filter-mapping>

web-app>

UserManage-servlet.xml

 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:mvc="http://www.springframework.org/schema/mvc"
 5        xmlns:context="http://www.springframework.org/schema/context"
 6        xsi:schemaLocation="
 7         http://www.springframework.org/schema/beans
 8         http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
 9         http://www.springframework.org/schema/mvc
10         http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
11         http://www.springframework.org/schema/context
12         http://www.springframework.org/schema/context/spring-context-4.2.xsd">
13 
14     
16     <context:component-scan base-package="org.usermanage.controller"/>
17 
18     
19     <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
20 
21     
22     <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
23 
24     
25     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
26         
27         <property name="prefix" value="/WEB-INF/content/jsp/">property>
28     bean>
29 
30     
31     <mvc:annotation-driven/>
32 
33     
34     <mvc:resources mapping="/*.html" location="WEB-INF/content/html/">mvc:resources>
35     <mvc:resources mapping="/*.js" location="WEB-INF/content/js/">mvc:resources>
36     <mvc:resources mapping="/*.css" location="WEB-INF/content/css/">mvc:resources>
37     <mvc:resources mapping="/login/*.css" location="WEB-INF/content/css/login/">mvc:resources>
38 
39 
40 beans>

spring-config.xml

<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: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/aop http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    
    
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>WEB-INF/config/jdbc.propertiesvalue>
                
            list>
        property>
    bean>

    
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        
        <property name="driverClass" value="${driver}">property>
        <property name="jdbcUrl" value="${url}">property>
        <property name="user" value="${username}">property>
        <property name="password" value="${password}">property>
        
        <property name="maxPoolSize" value="30"/>
        <property name="minPoolSize" value="10"/>
        
        <property name="autoCommitOnClose" value="false"/>
        
        <property name="checkoutTimeout" value="10000"/>
        
        <property name="acquireRetryAttempts" value="2"/>
    bean>

    
    <bean id="sqlsessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        
        <property name="configLocation" value="WEB-INF/config/mybatis-config.xml"/>
        <property name="dataSource" ref="dataSource"/>
        
        <property name="mapperLocations" value="classpath:org/usermanage/mapper/*.xml"/>
    bean>

    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        
        
        
        <property name="basePackage" value="org.usermanage.mapper"/>
    bean>

    
    <context:component-scan base-package="org.usermanage"/>

    
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    bean>

    
    

beans>

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>
        
        <setting name="useGeneratedKeys" value="true"/>

        
        <setting name="useColumnLabel" value="true"/>

        
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    settings>

    
    

    
    
    
    
    
    
    
    
    
    
    

    
    
    
    

configuration>

jdbc.properties

# jdbc连接信息
driver=com.mysql.jdbc.Driver
#url=jdbc:mysql://192.168.184.130:3306/gxrdb
url=jdbc:mysql://10.15.1.200:3306/gxrdb?useUnicode=true&characterEncoding=utf8
username=root
password=root

 

转载于:https://www.cnblogs.com/gongxr/p/8474691.html

你可能感兴趣的:(SSM三大框架整合配置(Spring+SpringMVC+MyBatis))