pom.xml, web.xml, springmvc.xml configuration files are what configuration? (Easy to understand)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_44296929/article/details/102553478

Introduction:
Use SpringMVC annotation framework Although we can avoid a lot of configurations, but only using annotations are not completely replace all of the configuration file, use the framework to build a project SpringMVC There are three main configuration file, pom.xml, the web.xml, springmvc.xml three, and as far as I am concerned, before SpringMVC on various configurations, always make silly things I could not tell in the end should be configured to put the configuration file which, let's talk about three configurations respectively The main configuration file what.

1, pom.xml file:

Written: pom.xml describes the project maven coordinates, dependencies , developers need to follow the rules, defect management systems, organizational and licenses, as well as all other relevant factors projects, project-level configuration file.

I understand: pom.xml file strictly speaking it should be said that Maven configuration file, the main purpose of the profile is dependent manner by the configuration management to make maven jar package, let maven to automatically import the package we need, pom.xml configuration file so the content is mainly dependent on the configuration of some.

Example: The following is the configuration SpringMVC dependency, I just give an example, with the increase in project functions, rely more and more.
Detailed pom.xml configuration file: Click for more

<dependencies>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-webmvc</artifactId>
		<version>3.2.8.RELEASE</version>
	</dependency>
</dependencies>

2, web.xml file:
First web.xml is an important configuration file java web project, but web.xml Java web project file is not required. web.xml is the future of our own project to create maven click java EE Tools manually generated, which in the project root directory /WEB-INF/web.xml location, web.xml file is used to configure: Welcome page, servlet, filter and so on . When your web project is useless to them, you can not web.xml file to configure your web project.

Example: Here are some basic configuration of web.xml: Why Learn: Comments on the file web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	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"
	version="2.5">
	<display-name>Demo</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>

	<!-- 配置HTML访问过滤器 -->
	<filter>
		<filter-name>HtmlAccessFilter</filter-name>
		<filter-class>cn.tedu.store.filter.HtmlAccessFilter</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>HtmlAccessFilter</filter-name>
		<url-pattern>*.html</url-pattern>
	</filter-mapping>

	<!-- 配置字符集编码过滤器 -->
	<filter>
		<filter-name>CharacterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>utf-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>CharacterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- 配置DispatcherServlet -->
	<servlet>
		<servlet-name>DispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<!-- 1.配置spring的配置文件 -->
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring-*.xml</param-value>
		</init-param>
		<!-- 2.启动Tomcat时即初始化该Servlet -->
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>DispatcherServlet</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
</web-app>

3, springmvc.xml file:

A. springmvc.xml profile is (recommended) configuration in src / main / resources under its official name is not provided (you can also define your own other names), which can also define multiple profiles according to their needs . Why know: the location and name of the configuration file

Example: Here is my project about the simple configuration: configure multiple xml configuration file.
Here Insert Picture Description
B. springmvc.xml mainly for frame SpringMVC some configurations in which there is disposed the main assembly of the scanning viewresolver, annotation drive, etc. interceptors , and Dao layer reads the configuration file, the configuration data source, the configuration file Interface etc. , in short, are some of the configuration for SpringMVC own framework. Specific configurations can simply refer to this article

Most of the above is my own understanding, if there are problems in a timely manner in order to correct the comments to tell me, if you have help, do not forget to point like oh, refills.

Guess you like

Origin blog.csdn.net/weixin_44296929/article/details/102553478