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. SAX解析文件

    import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import ja ...

  2. SSM框架下结合 log4j、slf4j打印日志

    首先加入log4j和slf4j的jar包 <!-- 日志处理 <!-- slf4j日志包--> <dependency> <groupId>org.slf4j ...

  3. TypeScript入门,使用TypeScript编写第三方控件的方式!

    这是一篇新手篇的typescript插件编写方式!!!! 源码完整地址:https://gitee.com/dissucc/typescriptLearn 1.环境安装 node下载 下载地址:htt ...

  4. 简单背包问题(0032)-swust oj

    简单背包问题(0032) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 5657 Accepted: 1714 Accepted 搜 ...

  5. Servlet交互【重定向 与 请求分派】详解

    Servlet交互 在serlvet中,需要调用另外一个资源来对浏览器的请求进行响应,两种方式实现: 调用HttpServletResponse.sendRedirect 方法实现 重定向 调用Req ...

  6. MySql的技术规范-企业版(来源于MySql官网)

    MySQL技术规范 Oracle MySQL云服务 MySQL数据库即服务 灵活的架构 开源 多线程 可插拔的存储引擎架构 InnoDB,NDB集群 MyISAM,合并,内存,存档 ANSI SQL标 ...

  7. 实践作业2:黑盒测试实践——安装配置测试工具 Day 3

    安装配置Katalon Studio工具 1.找下载Katalon链接,需要有效电子邮件才能激活Katalon账户,在我的Gmail里注册. 2.选择下载版本 3.下载完成后 ,转到计算机上的文件夹, ...

  8. windows平台下基于QT和OpenCV搭建图像处理平台

        在之前的博客中,已经分别比较详细地阐述了"windows平台下基于VS和OpenCV"以及"Linux平台下基于QT和OpenCV"搭建图像处理框架,并 ...

  9. appium+Linux环境安装配置

      背景:想要在Jenkins上跑appium的自动化测试,所以想要在Jenkins服务器(Linux远程)上安装appium服务,故而研究了一下appium+Linux下安装.虽然有无数的前辈踩过坑 ...

  10. jQuery选取所有复选框被选中的值并用Ajax异步提交数据

    昨天和朋友做一个后台管理系统项目的时候涉及到复选框批量操作,如果用submit表单提交挺方便的,但是要实现用jQuery结合Ajax异步提交数据就有点麻烦了,因为我之前做过的项目中基本上没用Ajax来 ...