spring mvc dispatcherservlet 在IntelliJ IDEA下初始化搭建Maven + Spr(2)

电脑杂谈  发布时间:2017-12-24 06:09:15  来源:网络整理

添加后,右下角会跳出提示,点击”Import Changes”完成maven依赖刷新。

这里写图片描述

或者点击Maven菜单中的刷新按钮亦可。

这里写图片描述

5.配置SpringMVC的配置文件。在WEB-INF目录下,新建一个Spring Config文件,命名为springmvc-config。

这里写图片描述

文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       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">

    <!-- spring自动扫描base-pack目录下的所有Java文件,包括子目录。如果扫描到有相关注解的类,就把这些类注册为Spring的bean。 -->
    <context:component-scan base-package="com.myz.controller"/>

    <!-- 配置annotation类型的处理映射器,它根据请求查找映射 -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
    <!-- 配置annotation类型的处理器适配器,完成对@RequestMapping标注方法的调用 -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
    <!-- 配置视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"/>
</beans>

<context:component-scan base-package="com.myz.controller"/>:

spring自动扫描base-pack目录下的所有Java文件,包括子目录。如果扫描到有相关注解的类,就把这些类注册为Spring的bean。

<bean/>:

配置annotation类型的处理映射器,它根据请求查找映射。

<bean/>:

配置annotation类型的处理器适配器,完成对@RequestMapping标注方法的调用


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-55466-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 陶仲文
      陶仲文

      人一身只要你努力就可以拼搏你想要的

    热点图片
    拼命载入中...