springmvc基本配置

xml配置

  1. 全局环境变量
1
2
3
4
5
6
7
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:conf.properties</value>
</list>
</property>
</bean>
  1. bean扫描
1
<context:component-scan base-package="cn.idea360" />
  1. 引入其他xml配置文件
1
<import resource="classpath*:weixin/spring-mybatis.xml"/>
  1. 读取配置文件
1
<context:property-placeholder location="classpath:conf.properties"/>
  1. servlet配置
1
2
3
4
5
6
7
8
9
10
11
12
13
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
  1. 编码配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
  1. 注解
1
2
<mvc:annotation-driven/>
<context:annotation-config />