[英]Spring FileSystemXmlApplicationContext getBeanDefinitionNames returns empty array
I have an active profile problem. 我的个人资料有问题。 Decided to look in debug mode on my context 决定在我的上下文中以调试模式查看
(profile indepenent contexts works in such way to in my case - (在我的情况下,个人资料无关的上下文可以-
getBeanDefinitionNames returns empty array). getBeanDefinitionNames返回空数组)。
new FileSystemXmlApplicationContext with mentioned file works without exceptions in code fragment mode. 带有提到的文件的新FileSystemXmlApplicationContext在代码片段模式下可以正常工作。
Code 码
new FileSystemXmlApplicationContext(
"D:\\Projects\\opti\dao\\src\\main\\resources\\contexts\\" +
"\\profiles\\test.xml")
This context with 这种情况与
getBeanDefinitionNames()
returns empty array. 返回空数组。
D:\\Projects\\opti\\dao\\src\\main\\resources\\contexts\\profiles\\test.xml D:\\ Projects \\ opti \\ dao \\ src \\ main \\ resources \\ contexts \\ profiles \\ test.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"
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>
Spring 4.2.5 春季4.2.5
D:\\Projects\\opti\\dao\\src\\main\\resources\\properties\\test-database.properties D:\\ Projects \\ opti \\ dao \\ src \\ main \\ resources \\ properties \\ test-database.properties
connection.driverClassName=org.hsqldb.jdbc.JDBCDriver
connection.url=jdbc:hsqldb:mem:test
connection.userName=sa
connection.password=
For use beans of a specific profile you should start the jvm with -Dspring.profiles.active=test, or setting spring.profiles.active=test as env variable System.setProperties(props) could be a way for configure it. 对于使用特定概要文件的Bean,您应该使用-Dspring.profiles.active = test来启动jvm,或者将spring.profiles.active = test设置为env变量System.setProperties(props)可以进行配置。
I hope that this can help you 希望对您有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.