我有一个活跃的侧写问题。决定在调试模式下查看我的上下文
(侧写的独立上下文在我的情况下是这样工作的-
getBeanDefinitionNames返回空数组)。
在代码片段模式下,带有上述文件的新FileSystemXmlApplicationContext可以正常工作。
代码
new FileSystemXmlApplicationContext(
"D:\\Projects\\opti\dao\\src\\main\\resources\\contexts\\" +
"\\profiles\\test.xml")这个上下文与
getBeanDefinitionNames()返回空数组。
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>春季4.2.5
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=发布于 2016-05-06 21:53:20
对于使用特定配置文件的bean,应该使用-Dspring.profiles.active=test启动jvm,或者将spring.profiles.active=test设置为env变量System.setProperties(props)可以配置它。
我希望这能帮到你
https://stackoverflow.com/questions/37081032
复制相似问题