Spring + Spring MVC + Mybatis框架整合相关配置

1    web.xml    配置

        1.配置一个监听器contextloaderlistener,让项目一启动就加载spring容器

              
                    contextConfigLocation
                    classpath:applicationContext.xml

              

              
                    org.springframework.web.context.ContextLoaderListener

              

        2.配置Spring MVC 的前端控制器dispatcherservlet。

             

    
    springDispatcherServlet
    org.springframework.web.servlet.DispatcherServlet
    
contextConfigLocation
location
    

    1
    

    
springDispatcherServlet
url

    

   3.配置字符过滤器CharacterEncodingFilter,请求类型过滤器HiddenHttpMethodFilter

            
                CharacterEncodingFilter
                org.springframework.web.filter.CharacterEncodingFilter
                
                    encoding
                    utf-8
                

                
                  forceRequestEncoding
                  true
                

                
                  forceResponseEncoding
                  true
                

              

              
                CharacterEncodingFilter
                /*
              

              
                HiddenHttpMethodFilter
                org.springframework.web.filter.HiddenHttpMethodFilter
              

             
                HiddenHttpMethodFilter
                /
              

            
           

2.  Spring MVC配置文件  dispatcherServlet-servlet.xml  的配置

                   

            1.扫描所以业务逻辑组件   要禁用掉默认的use-default-filters属性设置为false

                    
        
        
            

             2.配置视图扫描器

                
    
    
        


             3.

        
        
        
        

3.Spring 配置文件  applicationContext.xml的配置

        1.加载类路径下的 dbconfig.propertise文件,这是数据库的配置文件 

        

        2.配置扫描器 exclude:排除     这个自动扫描器只不扫描Controller类,其他都扫描

            

    

        3.配置数据源,可以使用c3p0     ComboPooledDataSource类

            




    

        4.配置和mybatis的整合,他能帮我们创建sqlSessionFactory

            






    

         5.配置扫描器  ,将mybatis接口的事现加入到ioc容器中

    

    

          6.事务控制相关

        



















          

你可能感兴趣的:(ssm)