编程语言
首页 > 编程语言> > java – 如何将spring xml从3.0转换为3.1使用bean:profile

java – 如何将spring xml从3.0转换为3.1使用bean:profile

作者:互联网

我有一个像3.0这样的xml:

        <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="${jdbc.driverClassName}" />
            <property name="url" value="${jdbc.internal.url}" />
            <property name="username" value="${jdbc.internal.username}" />        
            <property name="password" value="${jdbc.internal.password}"/>
        </bean>

我想在使用bean时将其转换为3.1:profile然而,当我尝试将其更改为:

        <beans profile="dev">
          <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
              <property name="driverClassName" value="${jdbc.driverClassName}" />
              <property name="url" value="${jdbc.internal.url}" />
              <property name="username" value="${jdbc.internal.username}" />        
              <property name="password" value="${jdbc.internal.password}"/>
        </bean>
        </beans>

我得到的错误如下:

Invalid content was found starting with element 'bean'. One of '{"http://www.springframework.org/schema/beans":beans}'

如何使用beans:profile,以便在活动配置文件为dev时仅调用此特定bean定义

更新
我的bean定义是:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd">

解决方法:

你必须把所有嵌套的< bean>配置文件最后的声明.这就是XML模式的定义方式,您必须遵守这一点.

也可以看看

> Spring Framework 3.1 M1 released

spring-beans-3.1.xsd has been updated to allow this nesting, but constrained to allow such elements only as the last ones in the file.

标签:java,spring-mvc,spring,spring-3
来源: https://codeday.me/bug/20190718/1494383.html