gpt4 book ai didi

java - 根据spring profile导入bean资源

转载 作者:行者123 更新时间:2023-12-02 03:25:52 27 4
gpt4 key购买 nike

下面是我的 spring 项目中 servlet-context.xml 的代码。如果配置文件是 prod,我想导入 demo.xml 文件;如果配置文件是 test,我想导入 demo-test.xml。

<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:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />

<beans profile="test">
<import resource="demo-test.xml"></import>
</beans>
<beans profile="prod">
<import resource="demo.xml"></import>
</beans>


<task:annotation-driven
executor="defaultExecutor"/>
<!-- add an exception handler here. -->

<task:executor id="defaultExecutor"
pool-size="50-200"
queue-capacity="1200"
keep-alive="10"
rejection-policy="CALLER_RUNS"/>

</beans:beans>

但我收到错误 The matching wildcard is strict, but no declaration can be found for element 'beans'.对于线 <beans profile="test">'resource' attribute should be defined对于 <import resource="demo-test.xml"></import>

基于error in spring xml config relating to bean profiles我什至尝试将上下文更改为“http://www.springframework.org/schema/beans/spring-beans-3.2.xsd”,但没有成功。有人可以帮助我理解此错误的含义以及如何解决此问题吗?

最佳答案

<beans:beans xmlns="http://www.springframework.org/schema/mvc" xml 文件顶部使用 mvc而不是beans ,这意味着默认命名空间是 mvc而不是beans 。或者,限定 bean 标签:使用 <beans:beans profile="test">...而不是<beans profile="test">...<beans:import resource...而不是<import resource... ,或者将默认命名空间更改为 beans按原样使用 xml

关于java - 根据spring profile导入bean资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56907696/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com