Spring5+Hibernate5+SpringMVC配置

记录一篇架构升级的文档,将配置过程遗漏的要点进行标注。以防自己日后遗忘。

Spring配置文件:applicationContext.xml

"1.0" encoding="UTF-8"?>
"http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.2.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">

	
	
    "com.demo.dao"/>
	"com.demo.service"/>
	"com.demo.*.dao"/>
	"com.demo.*.service"/>
	
	"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		"systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
		"ignoreResourceNotFound" value="true" />
	
	
    "propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    	"order" value="1"/>
    	"ignoreUnresolvablePlaceholders" value="true"/>
        "locations">
            
                classpath:jdbc.properties
            
        
    
     "dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">  
        "driverClass" value="${jdbc.driverClassName}"/>
        "jdbcUrl" value="${jdbc.url}"/>  
        "user" value="${jdbc.username}"/>  
        "password" value="${jdbc.password}"/>
        "initialPoolSize" value="${initialPoolSize}"/>  
        "maxStatementsPerConnection" value="${maxStatementsPerConnection}"/>  
        "maxPoolSize" value="${maxPoolSize}"/>  
        "minPoolSize" value="${minPoolSize}" />  
        "maxIdleTime" value="${maxIdleTime}" />  
     
    
      
    "sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    	"configLocation" value="classpath:hibernate.cfg.xml">
        "dataSource" ref="dataSource"/> 
        "hibernateProperties">
            
                "hibernate.dialect">org.hibernate.dialect.MySQL5Dialect  
                "hibernate.hbm2ddl.auto">none
              
                "hibernate.show_sql">false
                "hibernate.format_sql">true
                "jdbc.c3p0.testConnectionOnCheckout">${jdbc.c3p0.testConnectionOnCheckout}
                "jdbc.c3p0.testConnectionOnCheckin">${jdbc.c3p0.testConnectionOnCheckin}
                "jdbc.c3p0.testConnectionOnCheckout">${jdbc.c3p0.idleConnectionTestPeriod}
              
          
        "packagesToScan" value="com.demo"/>
    
      
    "com.demo" use-default-filters="false">  
        type="annotation" expression="org.springframework.stereotype.Controller"/>  
        type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>  
       
      
      
      
    "transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        "sessionFactory" ref="sessionFactory"/>
    
    
    "transactionManager"/>
    
       
    "txAdvice" transaction-manager="transactionManager">
    	
			"save*" propagation="REQUIRED" rollback-for="java.lang.RuntimeException"/>
			"update*" propagation="REQUIRED" rollback-for="java.lang.RuntimeException"/>
			"delete*" propagation="REQUIRED" rollback-for="java.lang.RuntimeException"/>
			"add*" propagation="REQUIRED" rollback-for="java.lang.RuntimeException"/>
			"query*" propagation="REQUIRED" read-only="true"/>
			"get*" propagation="REQUIRED" read-only="true"/>
			"find*" propagation="REQUIRED" read-only="true"/>
			"*" propagation="REQUIRED"/>
    	
    
    
    "txPointCut" expression="execution(* com.demo.service.*.*(..))"/>
	"txPointCut" advice-ref="txAdvice" />
    


复制代码

数据库jdbc.properties

jdbc.driverClassName=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/databaseName?serverTimezone=GMT%2B8&useSSL=false&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false
jdbc.username=root
jdbc.password=root
initialPoolSize=5
maxStatementsPerConnection=15
maxPoolSize=100
minPoolSize=2
maxIdleTime=1000
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=true
hibernate.format_sql=true
jdbc.c3p0.testConnectionOnCheckout=false
jdbc.c3p0.testConnectionOnCheckin=true
jdbc.c3p0.idleConnectionTestPeriod=3600
hibernate.hbm2ddl.auto=none
hibernate.cache.use_second_level_cache=false
hibernate.cache.use_query_cache=false
复制代码

SpringMVC配置文件:springMVC-servlet.xml

"1.0" encoding="UTF-8"?>
"http://www.springframework.org/schema/beans"   
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:context="http://www.springframework.org/schema/context"   
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"    
    xmlns:jee="http://www.springframework.org/schema/jee"   
    xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:aop="http://www.springframework.org/schema/aop"   
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xmlns:util="http://www.springframework.org/schema/util"  
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="  
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd  
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd  
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd  
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd  
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-4.3.xsd  
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd  
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd  
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
 	
    "com.demo.controller" />
    "com.demo.interceptor" />
    
    enable-matrix-variables="true"/>
     
    "org.springframework.web.servlet.view.InternalResourceViewResolver">
        
      	"prefix" value="/WEB-INF/view"/>       
        
        "suffix" value=".jsp"/>
    
    
    "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">    
        "messageConverters">      
                  
                "mappingJacksonHttpMessageConverter" />      
                  
              
      
    
   "mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">    
    "supportedMediaTypes">    
            
            application/json;charset=UTF-8
           
      
   
       
     "multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
         "defaultEncoding" value="UTF-8"/>
          
         "maxUploadSize" value="20480000"/>
     
	  
      
    "exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">  
        "exceptionMappings">  
              
                  
                "org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload  
              
          
    
         
	
	
		"/customer/**" />
		"/customer/public/*" />
		"com.demo.interceptor.AuthorizedInterceptor"/>
	
	
复制代码

hibernate配置文件:hibernate.cfg.xml

"1.0" encoding="UTF-8"?>
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
		"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">


           
        "/hibernate-conf/Customer.hbm.xml">
        ······
    

复制代码

web.xml配置:

"1.0" encoding="UTF-8"?>
"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">
	demoservice
	
		index.html
		index.htm
		index.jsp
	
  
  
    contextConfigLocation
    classpath*:applicationContext.xml
  

  
  
    org.springframework.web.context.ContextLoaderListener
  
  
  
    springMVC
    org.springframework.web.servlet.DispatcherServlet
    
        contextConfigLocation
        classpath*:springMVC-servlet.xml
    
    1
  
  
    springMVC
    /
  
  
  
    VisitFilter
    /*
  
  
    encodingFilter
    org.springframework.web.filter.CharacterEncodingFilter
    
        encoding
        UTF-8
    
    
        forceEncoding
        true
    
  
  
    encodingFilter
    /*
  
  
  
    openSession
    org.springframework.orm.hibernate5.support.OpenSessionInViewFilter
  
  
    openSession
    /*
  
复制代码

以上就是基本的配置文件的配置详情。如有错误请指正。

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

你可能感兴趣的:(Spring5+Hibernate5+SpringMVC配置)