JAVA主流框架SSM整合

一、前言

springMVC、Spring、Mybatis三大主流框架整合

二、工程创建

1.创建Maven的Web工程

目录结构


JAVA主流框架SSM整合_第1张图片
在这里插入图片描述

2.maven的jar包坐标

三个框架的都在一起导入了,和一些其他工具包




  4.0.0

  com.unclezs
  SSM_Integration
  1.0-SNAPSHOT
  war

  SSM_Integration Maven Webapp
  http://www.example.com

  
    UTF-8
    1.8
    1.8
    5.0.2.RELEASE
    1.6.6
    1.2.12
    5.1.6
    3.4.5
  

  
    
    
      org.aspectj
      aspectjweaver
      1.6.8
    

    
      org.springframework
      spring-aop
      ${spring.version}
    

    
      org.springframework
      spring-context
      ${spring.version}
    

    
      org.springframework
      spring-web
      ${spring.version}
    

    
      org.springframework
      spring-webmvc
      ${spring.version}
    

    
      org.springframework
      spring-test
      ${spring.version}
    

    
      org.springframework
      spring-tx
      ${spring.version}
    

    
      org.springframework
      spring-jdbc
      ${spring.version}
    

    
    junit
    junit
    4.12
      compile
    

    
      mysql
      mysql-connector-java
      ${mysql.version}
    

    
      javax.servlet
      servlet-api
      2.5
      provided
    

    
      javax.servlet.jsp
      jsp-api
      2.0
      provided
    

    
      jstl
      jstl
      1.2
    

    
    
      log4j
      log4j
      ${log4j.version}
    

    
      org.slf4j
      slf4j-api
      ${slf4j.version}
    

    
      org.slf4j
      slf4j-log4j12
      ${slf4j.version}
    
    
    
      org.mybatis
      mybatis
      ${mybatis.version}
    

    
      org.mybatis
      mybatis-spring
      1.3.0
    

    
      c3p0
      c3p0
      0.9.1.2
      jar
      compile
    
  

  
    SSM_Integration
    
      
        
          org.apache.maven.plugins
          maven-compiler-plugin
          3.2
          
            1.8
            1.8
            UTF-8
            true
          
        
      
    
  


三、整合SSM

1.spring配置文件

1.1 applicationContext.xml

配置Spring工厂,及mybatis整合



    
    
        
    

    
    
    
        
        
        
        
    
    
    
        
    
    
    
        
    
    
    
        
    

    
        
            
            
        
    
    
        
    


1.2 web.xml

spring容器创建、springmvc容器创建、中文乱码拦截器




  Archetype Created Web Application

  
  
    contextConfigLocation
    classpath:applicationContext.xml
  
  
  
  
    characterEncodingFilter
    org.springframework.web.filter.CharacterEncodingFilter
    
      encoding
      UTF-8
    
  
  
    characterEncodingFilter
    /*
  
  
  
    org.springframework.web.context.ContextLoaderListener
  
  
  
    dispatcherServlet
    org.springframework.web.servlet.DispatcherServlet
    
      contextConfigLocation
      classpath:springmvc.xml
    
    1
  
  
    dispatcherServlet
    /
  


1.3 log4j配置
# Set root category priority to INFO and its only appender to CONSOLE.
#log4j.rootCategory=INFO, CONSOLE            debug   info   warn error fatal
log4j.rootCategory=info, CONSOLE, LOGFILE

# Set the enterprise logger category to FATAL and its only appender to CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n

# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=axis.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n

2. SpringMVC配置文件



    
    
        
    
    
    
        
        
        
    
    
    
    
    
    
    


3.mybatis配置文件(spring已经整合)




    
        
            
            

            
        
    

    
    
        
        
        
    


你可能感兴趣的:(JAVA主流框架SSM整合)