配置时,可以将所有配置配置到xml文件中,也可以分成多个配置文件,然后使用节点导入其他配置文件。 但通常情况下,类似于IOC容器中的数据源、事务、Dao层、层以及其他框架的集成都放在配置文件中(而不是放在配置文件中)。
1、单独配置配置文件的目的:
配置配置文件的本质是添加一个单独的IOC容器来管理属于“自己”的bean的数据源Dao,让IOC容器专门管理属于自己的解析器等内容。
2.如何分离配置文件和配置文件
2.1 web.xml配置文件的配置
只需要在web.xml文件中配置监听器,启动容器的r,
contextConfigLocation
classpath:spring/applicationContext.xml
org.springframework.web.context.ContextLoaderListener
其中:/-.xml是配置文件和IOC容器。 主要是scan、dao包、数据源信息、事务等(另一种写法是使用.xml作为总文件,导入-dao.xml、-.xml、-mvc.xml)
2.2 web.xml配置文件的配置
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring/springmvc.xml
1
dispatcherServlet
/
其中.xml是 的配置文件,该文件中仅扫描到的包、查看解析器等。
3、一般来说,web.xml还会配置字节编码ter和两个支持Rest风格的过滤器等。
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
utf-8
forceEncoding
true
characterEncodingFilter
/*
hiddenHttpMethodFilter
org.springframework.web.filter.HiddenHttpMethodFilter
hiddenHttpMethodFilter
/*