我是否需要以下弹簧上下文文件中的所有以下xmlns和xsi:schemaLocation?
<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:jee="http://www.springframework.org/schema/jee"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<context:annotation-config />
<bean class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean id = "controller" class="simpleController"/>
</beans>
Run Code Online (Sandbox Code Playgroud)
因为我只是定义一个bean类只是使用
xmlns="http://www.springframework.org/schema/beans" and its corresponding schema location enough ?
Run Code Online (Sandbox Code Playgroud)
我不需要其他定义?如果不是,我什么时候需要使用这些定义?
dim*_*sli 10
bean命名空间,因为您使用XML来定义bean定义.context命名空间,因为您正在使用它来定义<context:annotation-config />oxm除非您通过依赖项执行xml 编组/解组操作,否则不需要命名空间spring-oxm.p除非您计划在bean定义中内联setter注入,否则不需要命名空间.tx除非您通过依赖项引入事务管理,否则不需要命名空间spring-tx.aop除非您通过依赖项执行任何AOP操作,否则不需要命名空间spring-aop.jee除非您计划执行任何Java EE操作(如jndi-lookup),否则不需要命名空间您只需要两个名称空间.
可以在应用程序上下文XML中删除任何其他命名空间.
此外,我建议您指向默认的XSD而不是版本特定的XSD.
<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">
Run Code Online (Sandbox Code Playgroud)