ssm完整配置文件之spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context.xsd
                           http://www.springframework.org/schema/mvc
                           http://www.springframework.org/schema/mvc/spring-mvc.xsd
                           http://www.springframework.org/schema/aop
                           http://www.springframework.org/schema/aop/spring-aop.xsd
">
    <!--可配置controller层的注解扫描、视图解析器、异常处理器、文件上传解析器、拦截器、哪些资源部拦截、MVC注解驱动-->
    <!--1、配置注解扫描,扫描controller-->
    <context:component-scan base-package="controller包路径"/>

    <!--2、配置视图解析器-->
    <bean id="ViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--JSP文件所在目录-->
        <property name="prefix" value="/pages/" />
        <!--文件的后缀名-->
        <property name="suffix" value=".jsp"/>
    </bean>

    <!--3、MVC注解驱动,开启对SpringMVC注解的支持-->
    <mvc:annotation-driven/>
    <!--让映射器、适配器和处理器生效(不配置默认也是生效)-->
    <!--<mvc:annotation-driven conversion-service="conversionService"/>-->

    <!--4、静态资源权限开放-->
    <!--    <mvc:default-servlet-handler/>-->
    <!--设置静态资源不过滤-->
    <mvc:resources mapping="/css/**" location="/css/"/>
    <mvc:resources mapping="/img/**" location="/img/"/>
    <mvc:resources mapping="/js/**" location="/js/"/>
    <mvc:resources mapping="/plugins/**" location="/plugins/"/>

    <!--支持AOP的注解支持,AOP底层使用代理技术
        JDK动态代理,要求必须有接口
        cglib代理,生成子类对象,proxy-target-class=“true"默认使用cglib的方式
        -->
    <aop:aspectj-autoproxy proxy-target-class="true"/>
</beans>

贴个文件夹结构,免得搞错了!
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SSM(Spring + SpringMVC + MyBatis)是一个基于Spring、Spring MVC和MyBatis的轻量级Java Web开发框架组合,它们在web应用中通常会使用`web.xml`文件来配置初始化参数和控制器映射等信息。`web.xml`是Servlet规范的一部分,主要负责定义应用程序的全局行为。 在SSM项目中,`web.xml`的主要配置包括以下几个部分: 1. **Servlet和Filter配置**:这里会定义Spring MVC的DispatcherServlet,以及可能使用的过滤器(如字符编码过滤器、日志记录过滤器等)。 ```xml <web-app> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> ... <filter> <filter-name>encodingFilter</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> ... </web-app> ``` 2. **Multipart Config**:如果项目需要处理文件上传,会配置MultipartResolver。 ```xml <multipart-config> <location>/WEB-INF/upload</location> <max-file-size>10MB</max-file-size> <max-request-size>100MB</max-request-size> </multipart-config> ``` 3. **ContextLoaderListener**:用于加载Spring的上下文。 ```xml <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> ``` 4. **Controller映射**:通过`<url-pattern>`标签指定请求URL和哪个控制器方法关联。 ```xml <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值