Spring、Spring-MVC、Mybatis、Mybatis-generator整合核心配置文件记录

Spring、Spring-MVC、Mybatis、Mybatis-generator整合核心配置文件记录

文章目录

  • Spring、Spring-MVC、Mybatis、Mybatis-generator整合核心配置文件记录
    • 1. spring.xml
    • 2. spring-mvc.xml
    • 3. mybatis-config.xml
    • 4. mybaits-generator.xml
    • 5. ehcach.xml
    • 6. web.xml

Spring、Spring-MVC、Mybatis、Mybatis-generator整合核心配置xml文件记录

1. spring.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"
       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">
    
    <context:property-placeholder location="classpath:dbConfig.properties"/>

    
    <context:component-scan base-package="com.ssm.dao,com.ssm.service"/>
beans>

2. spring-mvc.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:p="http://www.springframework.org/schema/p"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       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.0.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    
    <context:component-scan base-package="com.ssm.controller"/>
    
    
    <mvc:default-servlet-handler/>
    
    <mvc:annotation-driven/>

    
    <bean id="mappingJackson2HttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8value>
            list>
        property>
    bean>

    
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingJackson2HttpMessageConverter">ref>
            list>
        property>
    bean>
    
    <bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
        <property name="baseAddress" value="http://127.0.0.1:1231/"/>
    bean>
    <bean id="accountSynchronousService" class="com.ssm.controller.sysManagement.AccountSynchronousService">
    bean>
    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/views/" p:suffix=".jsp"/>

    
    
    <mvc:interceptors>
        
        
        <mvc:interceptor>
            
            <mvc:mapping path="/*.action"/>
            <mvc:mapping path="/*/*.action"/>
            <mvc:mapping path="/views/*.jsp"/>
            
            <mvc:exclude-mapping path="/emp/empLogin.action"/>
            <mvc:exclude-mapping path="/emp/ssoLogin.action"/>
            <mvc:exclude-mapping path="/login.jsp"/>
            <mvc:exclude-mapping path="/ssoLogin.jsp"/>
            <bean class="com.ssm.UserDefinedInterceptor.LoginInterceptor">bean>
        mvc:interceptor>
    mvc:interceptors>


    
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding">
            <value>UTF-8value>
        property>
        
        <property name="maxInMemorySize">
            <value>4096value>
        property>
    bean>

beans>

3. mybatis-config.xml


DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    
    <settings>
        
        <setting name="mapUnderscoreToCamelCase" value="true"/>
        
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    settings>
    <typeAliases>
        <package name="com.ssm.model"/>
    typeAliases>
    
    <plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor">plugin>
    plugins>
configuration>
  1. spring-mybatis.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">


    
    <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <property name="driverClassName" value="${jdbc_driverClassName}"/>
        <property name="url" value="${jdbc_url}" />
        <property name="username" value="${jdbc_username}" />
        <property name="password" value="${jdbc_password}" />
        
        <property name="initialSize" value="0" />
        
        <property name="maxActive" value="20" />
        
        
        
        <property name="minIdle" value="0" />
        
        <property name="maxWait" value="60000" />
        <property name="validationQuery" value="${validationQuery}" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />
        <property name="testWhileIdle" value="true" />
        
        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        
        <property name="minEvictableIdleTimeMillis" value="25200000" />
        
        <property name="removeAbandoned" value="true" />
        
        <property name="removeAbandonedTimeout" value="1800" />
        
        <property name="logAbandoned" value="true" />
        
        
        <property name="filters" value="mergeStat" />
    bean>


    
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        
        <property name="configLocation" value="classpath:mybatis-config.xml">property>
        <property name="dataSource" ref="dataSource"/>
        
        <property name="mapperLocations" value="classpath:com/ssm/mappers/*/*.xml">property>
    bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.ssm.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    bean>

    
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory">constructor-arg>
        <constructor-arg name="executorType" value="BATCH">constructor-arg>
    bean>


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


    
    <aop:config>
        
        <aop:pointcut id="txPoint" expression="execution(* com.ssm.service..*(..))"/>
        
        <aop:advisor advice-ref="transactionAdvice" pointcut-ref="txPoint"/>
    aop:config>

    
    
    
    <tx:advice id="transactionAdvice">
        <tx:attributes>
            
            <tx:method name="insert*">tx:method>
            <tx:method name="delete*">tx:method>
            <tx:method name="update*">tx:method>
            <tx:method name="modify*">tx:method>
            <tx:method name="import*">tx:method>
            <tx:method name="export*">tx:method>
            
            <tx:method name="get*" read-only="true">tx:method>
            <tx:method name="select*" read-only="true">tx:method>
            <tx:method name="find*" read-only="true">tx:method>
            <tx:method name="query*" read-only="true">tx:method>
            <tx:method name="count*" read-only="true">tx:method>
        tx:attributes>
    tx:advice>
beans>

4. mybaits-generator.xml


DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>
    
    <context id="DB2Tables" targetRuntime="MyBatis3">
        
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        commentGenerator>

        
        <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
                        connectionURL="jdbc:oracle:thin:@192.168.1.254:1521:orcl"
                        userId="familyAccount"
                        password="familyaccount">
        jdbcConnection>

        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        javaTypeResolver>
        
        <javaModelGenerator targetPackage="testMBG.entity" targetProject="./src/main/java/">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        javaModelGenerator>
        
        <sqlMapGenerator targetPackage="testMBG.mappers" targetProject="./src/main/java/">
            <property name="enableSubPackages" value="true"/>
        sqlMapGenerator>
        
        <javaClientGenerator type="XMLMAPPER" targetPackage="testMBG.dao" targetProject="./src/main/java/">
            <property name="enableSubPackages" value="true"/>
        javaClientGenerator>

        
        
        

        
       
        
        
        <table tableName="tb_user" domainObjectName="TbUser" enableSelectByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableCountByExample="false">table>

    context>
generatorConfiguration>

5. ehcach.xml


<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false">

    
    <diskStore path="D:\\ehcache" />
    <defaultCache maxElementsInMemory="1000" eternal="false"
                  timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
                  maxElementsOnDisk="10000000" diskPersistent="false"
                  diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />
ehcache>

6. web.xml


<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <display-name>ssmdisplay-name>
    
    <context-param>
        <param-name>contextConfigLocationparam-name>
        <param-value>classpath:spring.xml,classpath:spring-mybatis.xmlparam-value>
    context-param>
    
    <listener>
        <description>配置Spring监听器description>
        <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
    listener>
    <listener>
        <description>防止spring内存溢出监听器,可配置可不配description>
        <listener-class>org.springframework.web.util.IntrospectorCleanupListenerlistener-class>
    listener>

    
    <filter>
        <filter-name>characterEncodingFilterfilter-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>forceRequestEncodingparam-name>
            <param-value>trueparam-value>
        init-param>
        <init-param>
            <param-name>forceResponseEncodingparam-name>
            <param-value>trueparam-value>
        init-param>
    filter>
    <filter-mapping>
        <filter-name>characterEncodingFilterfilter-name>
        <url-pattern>/url-pattern>
    filter-mapping>

    
    <filter>
        <filter-name>hiddenHttpMethodFilterfilter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilterfilter-class>
    filter>
    <filter-mapping>
        <filter-name>hiddenHttpMethodFilterfilter-name>
        <url-pattern>/url-pattern>
    filter-mapping>

    
    <servlet>
        <description>Spring MVC servletdescription>
        <servlet-name>dispatcherServletservlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
        <init-param>
            <param-name>contextConfigLocationparam-name>
            <param-value>classpath:spring-mvc.xmlparam-value>
        init-param>
        <load-on-startup>1load-on-startup>
    servlet>
    <servlet-mapping>
        <servlet-name>dispatcherServletservlet-name>
        
        <url-pattern>*.actionurl-pattern>
    servlet-mapping>

    
    <servlet>
        <servlet-name>druidStatViewservlet-name>
        <servlet-class>com.alibaba.druid.support.http.StatViewServletservlet-class>
    servlet>
    <servlet-mapping>
        <servlet-name>druidStatViewservlet-name>
        <url-pattern>/druid/*url-pattern>
    servlet-mapping>

    
    <session-config>
        <session-timeout>30session-timeout>
    session-config>
    <welcome-file-list>
        <welcome-file>/login.jspwelcome-file>
        
    welcome-file-list>
web-app>

你可能感兴趣的:(spring,mvc,mybatis)