SSM框架+Log4j框架搭建

        创建完成后我的项目结构如下:

SSM框架+Log4j框架搭建_第1张图片

 

一、首先添加创建springmvc框架时项目依赖的jar包

      pom.xml的配置如下:

 


  4.0.0
  com.sysu
  test
  war
  1.0-SNAPSHOT

  test Maven Webapp
  http://maven.apache.org

  
    UTF-8
    3.1.2.RELEASE
  

  
    
      junit
      junit
      3.8.1
      test
    


      
      
          org.apache.logging.log4j
          log4j-api
          2.5
      
      
          org.apache.logging.log4j
          log4j-core
          2.5
      
      
          org.apache.logging.log4j
          log4j-web
          2.5
      
      
      
          org.slf4j
          slf4j-log4j12
          1.7.13
      


      
          org.springframework
          spring-webmvc
          4.2.4.RELEASE
      
      
          org.springframework
          spring-core
          4.2.4.RELEASE
      
      
          org.springframework
          spring-beans
          4.2.4.RELEASE
      
      
          org.springframework
          spring-context
          4.2.4.RELEASE
      
      
      
          org.springframework
          spring-context-support
          4.2.4.RELEASE
      
      
          org.springframework.data
          spring-data-jpa
          1.9.2.RELEASE
      


      
      
          org.springframework
          spring-test
          4.2.4.RELEASE
      


      
      
          org.apache.shiro
          shiro-core
          1.2.4
      
      
          org.apache.shiro
          shiro-web
          1.2.4
      
      
          org.apache.shiro
          shiro-cas
          1.2.4
      
      
          org.apache.shiro
          shiro-spring
          1.2.4
      
      
          org.apache.shiro
          shiro-ehcache
          1.2.4
      


      
      
          javax.servlet
          javax.servlet-api
          3.1.0
      
      
          javax.servlet.jsp
          jsp-api
          2.2
      


      
      
          org.mybatis
          mybatis
          3.3.0
      
      
      
          org.mybatis
          mybatis-spring
          1.2.3
      
      
          org.mybatis.generator
          mybatis-generator-core
          1.3.2
      
      
      
      
          commons-dbcp
          commons-dbcp
          1.4
      
      
      
          mysql
          mysql-connector-java
          5.1.38
      
      
          com.github.miemiedev
          mybatis-paginator
          1.2.17
      


      
          commons-fileupload
          commons-fileupload
          1.3.1
      

      
          jstl
          jstl
          1.2
      

      
      
          org.hibernate
          hibernate-validator
          5.1.3.Final
      


      
      
          org.quartz-scheduler
          quartz
          2.2.2
      
  

    
        
            
            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.2

                
                    
                    
                        mysql
                        mysql-connector-java
                        5.1.38
                    

                
                
                    true
                    true
                
            
        
    

    test



 

 

 

二、配置web.xml

      





Archetype Created Web Application



  encodingFilter
  org.springframework.web.filter.CharacterEncodingFilter
  
    encoding
    UTF-8
  
  
    forceEncoding
    true
  


  encodingFilter
  /*





  springmvc
  springmvc-dispatcher
  org.springframework.web.servlet.DispatcherServlet
  1




  springmvc-dispatcher
  /




  /


 

 

三、配置springmvc-dispatcher-servlet.xml

 

 




    
    

    
    

    
    

    
    

    
    


    
    
    
        
        
        
    

    
        
        
    


    
    

 

 

 

四、配置mybatis-context.xml

 




    
    

    
    
        
        
    

    
        
        
        
        
        
        
        
        
        
        
        
        
        
        

        
        

        
        
        
        
    


    
    
        
    

    
    
        
    

    
    

 

 

 

五、配置app-context.xml

 




    
    
        
            
                /WEB-INF/properties/jdbc.properties
            
        
    

 

 

 

六、配置jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=“”
jdbc.username=“”
jdbc.password=“”
#定义初始连接数
jdbc.initialSize=10
#定义最大连接数
#定义最大空闲
jdbc.maxActive=200
jdbc.maxIdle=20
#定义最小空闲
jdbc.minIdle=1
#定义最长等待时间
jdbc.maxWait=60000

 

七、集成Log4j

 

       log4j2.xml的配置如下:



	
		logs
		log
	

	
		
			
			
		

		
			
			
				
				
			
			
			
				
			
		
	

	
		
			
			
		
	

 

          使用方法如下:

package com.sysu;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * Created by Rongjie on 2016/3/13.
 * Guangzhou Baoshan Technology Co,Ltd.
 */
public class Test {

    private static Logger logger = LogManager.getLogger(Test .class);

    /**
     * 
     */
    @Test
    public void registerResource() {
        logger.info("-----test---------");

    }
 
}

 

 

 

 

 

 

 

你可能感兴趣的:(java,web系列)