Spring Tool Suite生成默认的MVC项目的配置文件问题
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项目的配置文件问题的更多相关文章
- STS(Spring Tool Suite)建立默认的spring mvc项目
引入响应的jar包解决报错: 由于国内的网络限制,下载会较慢.使用之前可自行更换maven的镜像路径,越近越好.
- spring tool suite (sts) 创建springmvc(没有实践)
摘自:STS(Spring Tool Suite)建立默认的spring mvc项目 老外的原创,网址:http://www.codejava.NET/frameworks/spring/spring ...
- 第一个使用Spring Tool Suite(STS)和Maven建立的Spring mvc 项目
一.目标 在这篇文章中.我将要向您展示怎样使用Spring Frameworks 和 Maven build创建您的第一个J2ee 应用程序. 二.信息 Maven是一个java项目的构建工具(或者自 ...
- Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目
Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目 Spring Tool Suite 是一个带有全套的Spring相关支持功能的Eclipse插件包. ...
- Spring MVC -- Spring Tool Suite和Maven(安装Tomcat、JDK)
Spring提供了自己的集成开发环境(IDE),称为Spring Tool Suite(STS),它可能是构建Spring应用程序的最佳IDE了.STS捆绑了Maven作为其默认依赖管理工具,因此不需 ...
- Spring Tool Suite(简称STS)针对SimpleDateFormat.pase函数的实参值不做检验,异常直接默认值之
Spring Tool Suite(简称STS)是 Spring 团队开发的一款基于Eclipse的IDE,旨在简化开发Spring MVC 应用的流程.可以自动生成spring相关的配置文件.比如a ...
- Spring Tool Suite 创建 SpringMVC+Maven 项目(一)!
使用Spring Tool Suite 创建 SpringMVC Web 项目,使用Maven来管理依赖! 首先对环境进行必要的配置 1. 配置必要的Java JDK版本! (菜单栏-窗口-首选项.) ...
- 用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 ...
- 使用spring tool suite(STS)工具创建spring boot项目和出现错误后的处理
一.先下载配置maven环境 1.下载地址:http://maven.apache.org/download.cgi windows下下载zip文件 2.解压后放到某个文件目录下 3.配置环境变量 ( ...
随机推荐
- Vocabulary & Phrase
Vocabulary A ANSI 美国国家标准学会,American National Standards Institute的缩写 a couple of [口语]少数的,几个 a s ...
- JAVA提高十四:HashSet深入分析
前面我们介绍了HashMap,Hashtable,那么还有一个hash家族,那就是HashSet;在讲解HashSet前,大家先要知道的是HashSet是单值集合的接口,即是Collection下面的 ...
- 基于树莓派的智能家居项目的设想与实现 Hestia
注:本人内容的准确性仅限于笔者写该篇文章时的情况,不保证后续与实际项目代码一致.实时内容还请关注Github项目托管页面:https://github.com/GenialX/hestia-serve ...
- Python 单向链表、双向链表
用面向对象实现Linkedlist链表 单向链表实现append.iternodes 双向链表实现append.pop.insert.remove.iternodes 单向链表与双向链表 单向链表: ...
- [线性筛]P1865 A % B Problem
题目背景 题目名称是吸引你点进来的 实际上该题还是很水的 题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行,每行两个整数 l,r 表示区间 输出格式: 对 ...
- ListView ,recycleView列表带进度条
实现上图功能有两种思路. 一:普通做法,更新item的数据,不停调用notifydatachange ; 二:各管自家刷新. 一个下载对应一个下载线程.线程持有对应item在Listview中的位置. ...
- poj1611 解题报告
并查集学习过之后做了几道相关联系,这里贴出1611 The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: ...
- 一个for循环打印二维数组
#include<stdio.h> #define MAXX 2 #define MAXY 3 void printarray() { ,,,,,}; ;i< MAXX*MAXY;i ...
- 基于 HTML5 Canvas 的 3D 模型列表贴图
少量图片对于我们赋值是没有什么难度,但是如果图片的量大的话,我们肯定希望能很直接地显示在界面上供我们使用,再就是排放的位置等等,这些都需要比较直观的操作,在实际应用中会让我们省很多力以及时间.下面这个 ...
- linux端口开放指定端口的两种方法
重要的事情说三遍,强烈建议使用第二种方法!第二种方法!第二!; 开放端口的方法: 方法一:命令行方式 1. 开放端口命令: /sbin/iptables -I INPUT ...