java - 属性 'profile' 不允许出现在元素 'beans:bean' 中

标签 java spring spring-mvc

不确定这里发生了什么。我的 XML bean 定义架构正在使用:

 <?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:jpa="http://www.springframework.org/schema/data/jpa"
         xmlns:beans="http://www.springframework.org/schema/beans"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:tx="http://www.springframework.org/schema/tx"
         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-3.2.xsd
        http://www.springframework.org/schema/data/jpa
    http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

定义中有问题的bean:

 <beans:bean profile="dev,qa,prod">
        <beans:bean parent="propertyConfigurer">
            <beans:property name="order" value="0"></beans:property>
            <beans:property name="locations">
                <beans:list>
                    <beans:value>classpath:messages.properties</beans:value>
                     <beans:value>classpath:common.properties</beans:value>
                    <beans:value>classpath*:META-INF/properties/local.properties</beans:value>
                </beans:list>
            </beans:property>
        </beans:bean>
</beans:bean>

但是,我得到:

 cvc-complex-type.3.2.2: Attribute 'profile' is not allowed to appear in element 'beans:bean'

任何想法

最佳答案

profile 属性必须出现在 beans 元素中,即:

<beans:beans profile="qa" ... >
    <bean id="..." ...></bean>
</beans>

可以有多个嵌套的 bean 元素:

<beans:beans>
    <bean id="..." ...></bean>
    <beans:beans profile="prod" ... >
        <bean id="..." ...></bean>
    </beans>
    <beans:beans profile="qa" ... >
        <bean id="..." ...></bean>
    </beans>
</beans>

关于java - 属性 'profile' 不允许出现在元素 'beans:bean' 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30562871/

相关文章:

java - 使用 Spring 在 Tomcat 启动期间委托(delegate)处理

java - 在 Spring RESTful Web 服务中接受 json 调用以及 XML

mysql - 无法使用 Spring Hibernate 连接到 MySQL 数据库

Java字段猜测

java - 与 androidx.work.logger 发生不兼容的ClassChangeError

java - 使用 POI 的 XSSF 和 SAX(事件 API)读取 Excel 工作表

java - Spring - Tomcat 配置 - 无法创建 .war 文件

java - 以什么方式调用方法?

java - 如何用java制作数据库监听器?

java - @ConfigurationProperties在spring中的使用