1、STS是开发Spring程序的首选,基于JavaEE的程序,我都用STS来开发,但是在生成默认的MVC项目时,其配置文件让人很讨厌,在许多选项上都会加一个beans,如<beans:beans>,<beans:bean>,<beans:property>,但是看标准的文档,都是用<beans>、<bean>之类的标签,很纳闷,甚至觉得是xsd版本的问题,后来观察了一个netbeans生成的spring项目配置文件,才恍然大悟。

2、默认生成的配置文件如下

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

<!-- DispatcherServlet Context: defines this servlet's request-processing
        infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving
        up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources
        in the /WEB-INF/views directory -->
    <beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

<context:component-scan base-package="com.shiyq.study" />
</beans:beans>
可以看出默认的命名空间为 xmlns="http://www.springframework.org/schema/mvc",这个就是常见的mvc空间,看下面的<annotation-driven/>和<resources>没有加mvc标签,就知道了,命名空间beans对应的是xmlns:beans="http://www.springframework.org/schema/beans",到这里就可以明白为什么会出现<beans:beans>模式的标签了,根标签为beans,还增加一个名称空间,所以解决办法也很简单,将默认的命名空间设置为beans对应的空间,默认的命名空间命名为"mvc",然后修改相应的标签,大致如下

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

<!-- DispatcherServlet Context: defines this servlet's request-processing
        infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving
        up static resources in the ${webappRoot}/resources directory -->
    <mvc:resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources
        in the /WEB-INF/views directory -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

<context:component-scan base-package="com.shiyq.study" />
</beans>

问题解决起来很简单,不过其实不改也没有太大影响,就是多写几个字母而已,但看起来清爽了不少,也算了解了一点xml的配置知识,所以随笔记下。

Spring Tool Suite生成默认的MVC项目的配置文件问题的更多相关文章

  1. STS(Spring Tool Suite)建立默认的spring mvc项目

    引入响应的jar包解决报错: 由于国内的网络限制,下载会较慢.使用之前可自行更换maven的镜像路径,越近越好.

  2. spring tool suite (sts) 创建springmvc(没有实践)

    摘自:STS(Spring Tool Suite)建立默认的spring mvc项目 老外的原创,网址:http://www.codejava.NET/frameworks/spring/spring ...

  3. 第一个使用Spring Tool Suite(STS)和Maven建立的Spring mvc 项目

    一.目标 在这篇文章中.我将要向您展示怎样使用Spring Frameworks 和 Maven build创建您的第一个J2ee 应用程序. 二.信息 Maven是一个java项目的构建工具(或者自 ...

  4. Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目

    Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目 Spring Tool Suite 是一个带有全套的Spring相关支持功能的Eclipse插件包. ...

  5. Spring MVC -- Spring Tool Suite和Maven(安装Tomcat、JDK)

    Spring提供了自己的集成开发环境(IDE),称为Spring Tool Suite(STS),它可能是构建Spring应用程序的最佳IDE了.STS捆绑了Maven作为其默认依赖管理工具,因此不需 ...

  6. Spring Tool Suite(简称STS)针对SimpleDateFormat.pase函数的实参值不做检验,异常直接默认值之

    Spring Tool Suite(简称STS)是 Spring 团队开发的一款基于Eclipse的IDE,旨在简化开发Spring MVC 应用的流程.可以自动生成spring相关的配置文件.比如a ...

  7. Spring Tool Suite 创建 SpringMVC+Maven 项目(一)!

    使用Spring Tool Suite 创建 SpringMVC Web 项目,使用Maven来管理依赖! 首先对环境进行必要的配置 1. 配置必要的Java JDK版本! (菜单栏-窗口-首选项.) ...

  8. 用spring tool suite插件创建spring boot项目时报An internal error occurred during: "Building UI model". com/google/common/

    本文为博主原创,未经允许不得转载 在用spring tool suite创建spring boot项目时,报一下异常: 查阅很多资料之后发现是因为装的spring tool suite的版本与ecli ...

  9. 使用spring tool suite(STS)工具创建spring boot项目和出现错误后的处理

    一.先下载配置maven环境 1.下载地址:http://maven.apache.org/download.cgi windows下下载zip文件 2.解压后放到某个文件目录下 3.配置环境变量 ( ...

随机推荐

  1. cgg之数据类型

    所有例子都在64为操作系统 Linux 2.6.30 x86_64 x86_64 x86_64 GNU/Linux 1.1整数 在stdint.h中定义一些看上去更明确的整数类型 #ifndef __ ...

  2. get和post与服务端的交互方式

    在网上看了不少关于get和post的文章,看到博主这个,现在手录下来. 原博客地址:http://www.cnblogs.com/warrior4236/p/5675756.html 一:B/S结构, ...

  3. centos6.9(Linux系统)安装VMware tools教程

    VMware tools是虚拟机上虚拟硬件的驱动,可以实现鼠标的无缝移出移入,剪贴板共享,共享文件夹等功能.很多的Linux系统初学者,在安装centos6.9系统时,没有安装VMware tools ...

  4. No bean named 'sqlSessionFactory' is defined

    其实程序给出这个错误已经很明确了,说你的sqlSessionFactory是未定义的. 首先你要查看一下自己的web.xml文件是否配置了application*.xml <!--设置sprin ...

  5. "虐待"过我的老师们,你们如今还好吗

    当皇城脚下的民生问题都这么难做的时候,其他地方又该如何保障呢? 京城“红黄蓝”出名了,京城发生锅炉大爆炸了,京城发生火灾了…… 聊天中,有一好友突然蹦出了一句话:“你看在皇城脚下都不安全了”. 久久我 ...

  6. Python 爬虫练习(二)爬取补天公益SRC厂商域名URL (2017年11月22日)

    介绍下: 补天是国内知名的漏洞响应平台,旨在企业和白帽子共赢. 白帽子在这里提交厂商漏洞,获得库币和荣誉,厂商从这里发布众测.获取漏洞报告和修复建议. 在2017年3月份之前,补天的厂商域名URL是非 ...

  7. Adobe阅读器漏洞(adobe_cooltype_sing)学习研究

    实验环境:Kali 2.0+Windows XP sp3+Adobe Reader 9.0.0 类别:缓冲区溢出 描述:这个漏洞针对Adobe阅读器9.3.4之前的版本,一个名为SING表对象中一个名 ...

  8. JavaWeb 学习之 JSTL

    上一篇博文我们讲解了 MVC 小案例,案例中包含了基本的增.删.改.查,对这个案例的有兴趣的伙伴可以自己动手实践一下,去复习一下或者说是学点新的知识!如果有已经看过且实践过的伙伴相信对 JSP 页面中 ...

  9. 超级有用的Vim命令

    你是否曾经烦恼,每次编辑vim文件,想要跳到一行结尾,需要按多次右键,每次想找到某个字符的位置,都得用肉眼去观察,每次想跳到文件结尾,都要按多次向下键.现在,你不必担心这些繁杂的过程,因为我们完全可以 ...

  10. linux文件、目录

    user用户 group用户组 others其他人用户信息保存在/etc/passwd [root@iZ25het8xn8Z ~]# ls -altotal 56dr-xr-x---. 3 root ...