ssm +maven +c3p0 整合各种配置文件笔记

开发工具:eclipse

使用技术:mybatis maven spring springmvc 

1.db.properties:

jdbc.driver = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://localhost:3306/user?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=utf8
jdbc.username = root
jdbc.password = root

2.log4j.properties:

 ### set log levels ###
log4j.rootLogger = debug ,  stdout ,  D ,  E

### \u8F93\u51FA\u5230\u63A7\u5236\u53F0 ###
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 =  %d{ABSOLUTE} %5p %c{1}:%L - %m%n

### \u8F93\u51FA\u5230\u65E5\u5FD7\u6587\u4EF6 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG ## \u8F93\u51FADEBUG\u7EA7\u522B\u4EE5\u4E0A\u7684\u65E5\u5FD7
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

### \u4FDD\u5B58\u5F02\u5E38\u4FE1\u606F\u5230\u5355\u72EC\u6587\u4EF6 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = logs/error.log ## \u5F02\u5E38\u65E5\u5FD7\u6587\u4EF6\u540D
log4j.appender.D.Append = true
log4j.appender.D.Threshold = ERROR ## \u53EA\u8F93\u51FAERROR\u7EA7\u522B\u4EE5\u4E0A\u7684\u65E5\u5FD7!!!
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%

3.applicationContext.xml配置:


    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    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.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd">

    
             base-package="com.gaozhuan.service com.gaozhuan.dao">
    
             location="classpath:db.properties" />
    
             class="com.mchange.v2.c3p0.ComboPooledDataSource">
        
        
        
        
    

    
             class="org.mybatis.spring.SqlSessionFactoryBean">
        
        
                     value="classpath:com/gaozhuan/mapper/*.xml">
                     value="classpath:mybatis-config.xml">
    

    
    
        
                     value="sqlSessionFactory">
    

    
    


 

4.mybatis.xml配置:



    
    
        
    

    
    
        
        
    


 

5.springmvc-context.xml配置:


    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    
    

    
             base-package="com.gaozhuan.controller">

    
    
    
             class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        
        
    

    
    
        
                             class="org.springframework.http.converter.StringHttpMessageConverter">
                
            
        

    

    

 

6.web.xml配置:


    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    ssm_demo
    
        index.jsp
        index.html
        index.htm
        default.html
        default.htm
        default.jsp
    

    
    
        characterEncoding
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        

    

    
        characterEncoding
        /*
    

    
    
        dispatcherServlet
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:springmvc-context.xml
        

        1
    

    
        dispatcherServlet
        /
    

    
    
        org.springframework.web.context.ContextLoaderListener
    

    
        contextConfigLocation
        classpath:applicationContext.xml
    

    
    
        org.springframework.web.util.Log4jConfigListener
    

    
        log4jConfigLocation
        classpath:log4j.properties
    


7.pom.xml:

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    4.0.0
    com.gaozhuan
    ssm_demo
    war
    0.0.1-SNAPSHOT
    ssm_demo Maven Webapp
    http://maven.apache.org
    
        
            junit
            junit
            3.8.1
            test
        

        
        
            org.springframework
            spring-context
            4.3.10.RELEASE
        

        
        
            org.springframework
            spring-core
            4.3.10.RELEASE
        

        
        
            org.springframework
            spring-beans
            4.3.10.RELEASE
        

        
        
            org.springframework
            spring-web
            4.3.10.RELEASE
        

        
        
            org.springframework
            spring-webmvc
            4.3.10.RELEASE
        

        
        
            org.mybatis
            mybatis
            3.4.6
        

        
        
            org.mybatis
            mybatis-spring
            1.3.0
        

        
        
            mysql
            mysql-connector-java
            5.1.20
        

        
        
            javax.servlet
            jstl
            1.2
        

        
        
            org.aspectj
            aspectjweaver
            1.9.1
        

        
        
            log4j
            log4j
            1.2.17
        

        
        
            org.slf4j
            slf4j-api
            1.7.25
        

        
        
            com.mchange
            c3p0
            0.9.5.2
        

        
        
            org.springframework
            spring-tx
            4.3.10.RELEASE
        

        
        
            org.springframework
            spring-jdbc
            4.3.10.RELEASE
        

    
    
        ssm_demo
    


 

8 分包结构:

 

ssm +maven +c3p0 整合各种配置文件笔记_第1张图片

 

 

遇到的问题汇总:

1.log4j.properties文件中有个{ 1 }| 多了个空格;

2.applicationContext.xml文件中使用的c3p0jar包版本有问题 重新更换。

3.maven中jar包文件忘记导入spring-jdbc.jar 包。

4. 测试的过程中使用了一个跳转url:user/loginPage 结果在表单提交的时候只能提交的路由为“login” 不能是“user/login” 否则跳转链接会变成 user/user/login找不到页面

5.db.properties文件中的

utf8后面多了个空格 出现启动有问题 页面显示为源代码

6. ssm +maven +c3p0 整合各种配置文件笔记_第2张图片

注意上面红圈里面的值不能写错,否则数据库链接有问题,后面的sqlsessionfactoryBean 很多注解都不可使用 

你可能感兴趣的:(工作笔记,ssm,mybatis,springMVC,spring,maven)