Spring概要文件XML bean配置需要位于文件的开头
当使用DEV profile时,使用下面的Spring配置加载Spring概要文件XML bean配置需要位于文件的开头,spring,Spring,当使用DEV profile时,使用下面的Spring配置加载com.Test2,在所有其他情况下加载com.Test1: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sp
com.Test2
,在所有其他情况下加载com.Test1
:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="bean1"
class="com.Test1">
</bean>
<beans profile="DEV">
<bean id="bean1"
class="com.Test2">
</bean>
</beans>
</beans>
为什么会报告此错误?为什么要求在文件开头设置弹簧外形?报告错误是因为,根据,在第二种情况下,元素的顺序不正确: 如您所见,任何
声明都必须在任何嵌套的
之前提供
该限制也在以下文件中指出:
也可以避免在同一文件中拆分和嵌套
元素,如下例所示:
springbean.xsd
被限制为只允许文件中最后一个元素。这将有助于提供灵活性,而不会导致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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<beans profile="DEV">
<bean id="bean1"
class="com.Test1">
</bean>
</beans>
<bean id="bean1"
class="com.Test2">
</bean>
</beans>
Invalid content was found starting with element '{"http://www.springframework.org/schema/beans":bean}'. One of '{"http://www.springframework.org/schema/beans":beans}' is expected.