Idea maven整合Spring5+springMVC+mybatis3.4.6

闲着无聊整合下框架,发现好多坑,记录下

用的是maven
Idea maven整合Spring5+springMVC+mybatis3.4.6_第1张图片

next
Idea maven整合Spring5+springMVC+mybatis3.4.6_第2张图片
继续next
Idea maven整合Spring5+springMVC+mybatis3.4.6_第3张图片
Idea maven整合Spring5+springMVC+mybatis3.4.6_第4张图片

pom.xml(jar 包没什么好说的)




    4.0.0

    com.mySSM.SSM
    SSM
    1.0-SNAPSHOT
    war

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

    
        UTF-8
        1.7
        1.7
        5.0.6.RELEASE
    

    
        
        
            junit
            junit
            4.11
            test
        

        
        
            javax.servlet
            jstl
            1.2
        

        
        
            javax.servlet
            javax.servlet-api
            4.0.1
            provided
        

        
        
            org.apache.logging.log4j
            log4j-core
            2.11.0
        
        
            org.apache.logging.log4j
            log4j-slf4j-impl
            2.11.0
        


        
        
            com.fasterxml.jackson.core
            jackson-core
            2.9.5
        
        
            com.fasterxml.jackson.core
            jackson-databind
            2.9.5
        

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

        
            org.springframework
            spring-core
            ${spring.version}
        
        
            org.springframework
            spring-beans
            ${spring.version}
        
        
            org.springframework
            spring-web
            ${spring.version}
        
        
            org.springframework
            spring-test
            ${spring.version}
            test
        
        
            org.springframework
            spring-aop
            ${spring.version}
        
        
            org.springframework
            spring-orm
            ${spring.version}
        
        
            org.springframework
            spring-jdbc
            ${spring.version}
        
        
            org.springframework
            spring-tx
            ${spring.version}
        
        
            org.springframework
            spring-expression
            ${spring.version}
        
        
            org.springframework
            spring-webmvc
            ${spring.version}
        

        

        
        
            org.mybatis
            mybatis
            3.4.6
        

        
            org.mybatis.generator
            mybatis-generator-maven-plugin
            1.3.6
        


        
            org.mybatis
            mybatis-spring
            1.3.2
        

        
        
            com.oracle
            ojdbc6
            11.2.0.3
        

        

        
        
            commons-io
            commons-io
            2.6
        
        
            org.apache.commons
            commons-lang3
            3.7
        
        
            org.apache.commons
            commons-dbcp2
            2.3.0
        
        
            commons-fileupload
            commons-fileupload
            1.3.3
        


    

    
        SSM
        
            
                
                    maven-clean-plugin
                    3.0.0
                
                
                
                    maven-resources-plugin
                    3.0.2
                
                
                    maven-compiler-plugin
                    3.7.0
                
                
                    maven-surefire-plugin
                    2.20.1
                
                
                    maven-war-plugin
                    3.2.0
                
                
                    maven-install-plugin
                    2.5.2
                
                
                    maven-deploy-plugin
                    2.8.2
                
                
                    org.mybatis.generator
                    mybatis-generator-maven-plugin
                    1.3.6
                    
                        src/main/resources/generatorConfig.xml
                        true
                        true
                    
                
            
        

        
        
            
                src/main/java
                
                    **/*.xml
                
            
        
    

这边要在build中加


                src/main/java
                
                    **/*.xml
                
            
不然mapper.xml加载不了
用的mybatis-generator自动生成所以加了maven-plugin,


                    org.mybatis.generator
                    mybatis-generator-maven-plugin
                    1.3.6
                    
                        src/main/resources/generatorConfig.xml
                        true
                        true
                    
                

web.xml



    Archetype Created Web Application

    
        index.jsp
    

    
    
        contextConfigLocation
        classpath*:applicationContext-springMVC.xml,classpath*:applicationContext-mybatis.xml
    

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

    
    
        org.springframework.web.context.ContextLoaderListener
    
    
    
        org.springframework.web.util.IntrospectorCleanupListener
    

    
   
       SpringMVC
       org.springframework.web.servlet.DispatcherServlet
       
           contextConfigLocation
           classpath*:applicationContext-springMVC.xml,classpath*:applicationContext-mybatis.xml
       
       1
   
    
        SpringMVC
        /
    

    
    
        120
    


在SpringMVC控制器url拦截那边,不能写/*,不然jsp会显示源码, 
  
springmvc浏览器显示jsp源码解决办法
applicationContext-mybatis.xml



    
    
        
            
                classpath*:jdbc.properties
            
        
    

    
    
        
        
        
        
        
        
        
        
        
        
        
    

    
    
        
        
        
        
        
        
        
    

    
        
    

    
    
        
        
        
        
    
    
    
        
        
    
    
    

applicationContext-springMVC.xml



    
    

    
    
    
    
    

    
    
        
        
        
        
        
    

jdbc.properties
db.driverClassName=oracle.jdbc.driver.OracleDriver
db.url=jdbc:oracle:thin:@//localhost:1521/orcl
db.username=bocc
db.password=boccpass
db.maxTotal=1500
db.minIdle=10
db.maxWaitMillis=60000
db.validationQuery=SELECT 1 FROM DUAL
db.testOnBorrow=true
db.poolPreparedStatements=true
db.defaultAutoCommit=false

log4j2.xml





    
    
        
        
            
            
        
        
        
            
        
        
        
            
            
            
            
                
                
            
        
        
            
            
            
                
                
            
            
            
        
        
            
            
            
                
                
            
        
    
    
    
        
        
        
        
            
            
            
            
        
    

mybatis自动生成代码
generatorConfig.xml    
xml version="1.0" encoding="utf-8" ?>
generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">


    
    resource="jdbc.properties"/>

    location="C:\Users\10408\.m2\repository\com\oracle\ojdbc6\11.2.0.3\ojdbc6-11.2.0.3.jar"/>

    id="default" targetRuntime="MyBatis3">

        
        
            name="suppressDate" value="true"/>
            name="suppressAllComments" value="true"/>
        

        
                        driverClass="oracle.jdbc.driver.OracleDriver"
                connectionURL="jdbc:oracle:thin:@//localhost:1521/orcl"
                userId="bocc"
                password="boccpass">
        


        
        
            name="forceBigDecimals" value="false"/>
        

        
        targetPackage="com.mySSM.user.bean" targetProject="src/main/java">
            
            name="trimStrings" value="true"/>
        

        targetPackage="com.mySSM.user.bean" targetProject="src/main/java"/>

        type="XMLMAPPER" targetPackage="com.mySSM.user.dao" targetProject="src/main/java">
            
        

        
        tableName="T_USER" domainObjectName="User"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"/>

    

这边我试着用配置文件的方式去引入驱动包路径和数据库的一些配置,但是都报错了。没办法就直接写死进来了
Idea maven整合Spring5+springMVC+mybatis3.4.6_第5张图片

配置tomcat。。。。。

启动项目网页能出来就说明整合OK了

你可能感兴趣的:(Idea maven整合Spring5+springMVC+mybatis3.4.6)