我是Spring的新手.有一件事让我感到困惑的是,有时我会看到带有版本化模式的XML配置文件,但有时会看到非版本化模式.例如,有时我会看到类似的东西
<?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-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="base.package"/>
</beans>
Run Code Online (Sandbox Code Playgroud)
有时像这样:
<?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">
<context:annotation-config/>
<context:component-scan base-package="base.package"/>
</beans>
Run Code Online (Sandbox Code Playgroud)
请注意,两个示例中的spring-beans和spring-context模式不同.
所以,我的问题是,你会使用哪种风格?为什么?特别是,版本化架构将来是否会变得不可用,并且当Spring更新架构时,非版本化架构是否会与当前应用程序保持兼容?
一个附带问题是,我在哪里可以找到版本化的弹簧模式列表?
非常感谢!
我知道这是重复的,你们会因为它而责备我,但在阅读完所有帖子后我没有得到适当的解决方案.
我试图在Spring Source Tool Suite中构建一个Spring Template应用程序.我收到以下错误.
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自ServletContext资源[/WEB-INF/spring/appServlet/servlet-context.xml]的XML文档中的第16行无效; 嵌套异常是org.xml.sax.SAXParseException:cvc-complex-type.2.4.c:匹配的通配符是strict,但是没有为元素'resources'找到声明.
我的root-context.xml是这样的:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.0.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
</beans>
Run Code Online (Sandbox Code Playgroud)
如果我的申请中缺少jar文件,请告诉我.
这些是我在我的应用程序中唯一的jar文件:
displaytag-1.0-b3.jar,spring-2.0.6.jar,spring-asm-3.0.3.RELEASE.jar,spring-beans-3.0.3.RELEASE. jar,spring-context-3.0.3.RELEASE.jar,spring-core-3.0.3.RELEASE.jar,spring-expression-3.0.3.RELEASE.jar,spring-hibernate3-2.0.8.jar,spring- web-3.0.3.RELEASE.jar&spring-webmvc-3.0.3.RELEASE.jar
这是我的servlet-context.xml
<?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-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC …Run Code Online (Sandbox Code Playgroud)