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.配置环境变量 ( ...
随机推荐
- [转载] PHP 线程,进程和并发
转载自http://chenpeng.info/html/3021 进程 进程是什么?进程是正在执行的程序:进程是正在计算机上执行的程序实例:进程是能分配给处理器并由处理器执行的实体. 进程一般会包括 ...
- [转载] zookeeper应用——集中配置管理系统的实现
转载自http://blog.csdn.net/huangfengxiao/article/details/8844239 1 场景描述 参考http://www.ibm.com/developerw ...
- 使用XML设计某大学主页站点地图--ASP.NET
一.使用XML设计某大学主页站点地图步骤如下 1.创建一个空网站,在项目文件上右击,然后[添加新项],选择[站点地图],新建一个可默认为Web.sitemap的文件. 2.在Web.sitemap里修 ...
- cgg之类型转换
3.类型转换 3.1算术类型转换 编译器默认的隐式转换等级: long double >double >float >long long >long >int >c ...
- .NET自带缓存机制实例
using System;using System.Web;using System.Web.Caching;using System.Collections.Generic;using System ...
- laravel5.3统计 withCount()方法的使用
在laravel5.3之后可以使用withCount()这个方法. 注意:一定要是5.3版本之后,5.2和5.1都会报方法未定义 举个栗子: App\Post::withCount('comments ...
- idea+scala+spark遇到的一些问题
1.windows中以本地模式运行spark遇到"Could not locate executable null\bin\winutils.exe in the Hadoop binari ...
- Java计算字符串中字母出现的次数
话不多说,直接上代码........... public static void main(String[] args) { String str="I'm go to swimming&q ...
- php的定界符<<<eof的问题
在php的编程过程中难免会遇到输出大段的html和javascript脚本的情况,可都放在具体的地方的时候,路由不好处理,而且比较浪费时间 如果按照传统的输出方法,按照字符串输出的话,需要大量的转义字 ...
- 利用python对excel进行数据剔除
需求分析: 判断excel2表中的某个唯一字段是否满足条件,如果满足条件,就在excel1中进行查询,若存在excel中,就将该数据进行剔除. python脚本的实现: from __future__ ...