【Spring笔记】11、拆分Spring配置文件

    java项目:

        applicationContext1.xml
        applicationContext2.xml
        applicationContext3.xml

ApplicationContext conext = new ClassPathXmlApplicationContext("applicationContext3.xml") ;


    Web项目:

   根据什么拆分?
        i.三层结构   
            UI(html/css/jsp  、Servlet)  applicationController.xml
            Service :applicationService.xml
            Dao:applicationDao.xml
            公共 数据库:applicationDB.xml

        ii.功能结构
            学生相关配置 applicationContextStudent.xml  
            班级相关配置 applicationContextClass.xml 

        合并:如何将多个配置文件 加载
            (1)web.xml

  
          
  contextConfigLocation
          
              classpath:applicationContext.xml,
              classpath:applicationContext-Dao.xml,
              classpath:applicationContext-Service.xml,
              classpath:applicationContext-Controller.xml
          
  


        (2)推荐

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

        (3)只在web.xml中加载主配置文件,

        
              classpath:applicationContext.xml
         

             然后在主配置问加中,加载其他配置文件

 

spring整合三层:

【Spring笔记】11、拆分Spring配置文件_第1张图片
        
            
                    

        

    

 

你可能感兴趣的:(javaweb,Spring)