首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Spring FileSystemXmlApplicationContext getBeanDefinitionNames返回空数组

Spring FileSystemXmlApplicationContext getBeanDefinitionNames返回空数组
EN

Stack Overflow用户
提问于 2016-05-06 20:38:09
回答 1查看 253关注 0票数 0

我有一个活跃的侧写问题。决定在调试模式下查看我的上下文

(侧写的独立上下文在我的情况下是这样工作的-

getBeanDefinitionNames返回空数组)。

在代码片段模式下,带有上述文件的新FileSystemXmlApplicationContext可以正常工作。

代码

代码语言:javascript
运行
复制
new FileSystemXmlApplicationContext(
            "D:\\Projects\\opti\dao\\src\\main\\resources\\contexts\\" +
"\\profiles\\test.xml")

这个上下文与

代码语言:javascript
运行
复制
getBeanDefinitionNames()

返回空数组。

D:\Projects\opti\dao\src\main\resources\contexts\profiles\test.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>
<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-4.2.xsd
http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context.xsd">
<beans profile="test">
    <context:property-placeholder properties-ref="properties" ignore-resource-not-found="false"/>
    <bean id="properties" lazy-init="false"
              class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>classpath*:properties/test-database.properties</value>
            </list>
        </property>
    </bean>
</beans>
</beans>

春季4.2.5

D:\Projects\opti\dao\src\main\resources\properties\test-database.properties

代码语言:javascript
运行
复制
connection.driverClassName=org.hsqldb.jdbc.JDBCDriver
connection.url=jdbc:hsqldb:mem:test
connection.userName=sa
connection.password=
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-06 21:53:20

对于使用特定配置文件的bean,应该使用-Dspring.profiles.active=test启动jvm,或者将spring.profiles.active=test设置为env变量System.setProperties(props)可以配置它。

我希望这能帮到你

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37081032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档