SpringMvc基本环境配置

Maven依赖

基于Maven管理的SpringMvc项目基础的依赖

pom.xml




4.0.0
war

FcoinAPI3
FcoinAPI3
FcoinAPI3
1.0-SNAPSHOT

  
    
      
        
        
        org.mortbay.jetty
        maven-jetty-plugin
        6.1.7
        
          
            
              8888
              30000
            
          
          ${project.build.directory}/${pom.artifactId}-${pom.version}
          /
        
      
        
          
            org.apache.maven.plugins
            maven-compiler-plugin
            
              
              1.8
              
              1.8
            
        
    
  

  
    
    
    
      org.springframework
      spring-core
      4.1.7.RELEASE
    
    
      org.springframework
      spring-beans
      4.1.7.RELEASE
    
    
      org.springframework
      spring-context
      4.1.7.RELEASE
    
    
    
      org.springframework
      spring-jdbc
      4.1.7.RELEASE
    
    
      org.springframework
      spring-tx
      4.1.7.RELEASE
    
    
    
      org.springframework
      spring-web
      4.1.7.RELEASE
    
    
      org.springframework
      spring-webmvc
      4.1.7.RELEASE
    
    
    
      org.springframework
      spring-test
      4.1.7.RELEASE
    

    
    
      junit
      junit
      4.11
    

    
    
      org.mybatis
      mybatis
      3.3.0
    
    
      org.mybatis
      mybatis-spring
      1.2.3
    

    
    
      taglibs
      standard
      1.1.2
    
    
      jstl
      jstl
      1.2
    
    
      com.fasterxml.jackson.core
      jackson-databind
      2.5.4
    
    
      javax.servlet
      javax.servlet-api
      3.1.0
    

    
    
      mysql
      mysql-connector-java
      8.0.13
      runtime
    

    
    
      c3p0
      c3p0
      0.9.1.2
    

    
    
      redis.clients
      jedis
      2.7.3
    
    
      com.dyuproject.protostuff
      protostuff-core
      1.0.8
    
    
      com.dyuproject.protostuff
      protostuff-runtime
      1.0.8
    

    
    
      commons-collections
      commons-collections
      3.2
    

    
    
      commons-codec
      commons-codec
      1.9
    

    
    
      log4j
      log4j
      1.2.17
    


  



初始配置文件web.xml

web.xml中配置SpringMvc核心控制器,并初始化相关功能配置



  
  
  
    Dispatcher
    org.springframework.web.servlet.DispatcherServlet
    
    
      
      contextConfigLocation
      classpath:spring/spring-*.xml
    
  
  
    Dispatcher
    
    /
  

  
  
  
    webAppRootKey
    webapp.root
  

  
  
    log4jConfigLocation
    classpath:log4j.properties
  
  
  
    log4jRefreshInterval
    3000
  
  
    org.springframework.web.util.Log4jConfigListener
  



SpringMvc相关配置文件spring-*.xml

配置SpringMvc相关功能,如:数据连接池的配置,开启注解配置,核心监听器配置,配置注解扫描包,开启事务注解,配置事务管理器,bean容器等等。

  1. spring-mvc.xml,spring核心配置


    
    
    
    

    
    

    

    
    
        
        
        
    



    
    

  1. spring-dao.xml,数据库连接池配置


    
    
    

    
    
        
        
        
        
        

        
        
        
        
        
        
        
        
        
    

    
    
        
        
        
        
        
        
        
        
    

    
    
        
        
        
        
    

  1. spring-service.xml,事务相关配置


    
    

    
    

    
    
        
        
    

    
    

  1. spring-bean.xml,bean容器




    
    
        
        
        
    
    
    

    
    
    

    
    

    
    

    
    

    
    
    



各资源文件properties配置

  1. jdbc.properties,数据库连接参数配置
#mysql5.0版本配置
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3308/An?useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=

#mysql8.0版本配置
jdbc8.driver=com.mysql.cj.jdbc.Driver
#需要加入时区UTC;不需要建立SSL连接的,需要显示关闭
jdbc8.url=jdbc:mysql://localhost:3306/An?useSSL=false&serverTimezone=UTC
jdbc8.username=root
jdbc8.password=
  1. log4j.properties,日志参数配置
###设置日志级别###
log4j.rootLogger = debug,stdout,D,E

### 输出信息到控制台 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n

### 输出DEBUG 级别以上的日志到=E://logs/error.log ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = D://火币OK币API//Fcoinlog/DEBUG.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG 
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n

### 输出ERROR 级别以上的日志到=E://logs/error.log ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =D://火币OK币API//Fcoinlog/ERROR.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR 
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n
  1. Mybatis-cofig.xml,持久化层框架配置



    
    
        
        

        
        

        
        
    

你可能感兴趣的:(SpringMvc基本环境配置)