我需要从程序运行之前我不知道的位置将一些属性加载到Spring上下文中.
所以我认为,如果我有一个没有位置的PropertyPlaceholderConfigurer,它会my.location从系统属性读入,然后我可以在上下文中使用该位置:property-placeholder
像这样
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<context:property-placeholder location="${my.location}"/>
Run Code Online (Sandbox Code Playgroud)
但这不起作用也不行 location="classpath:${my.location}"
保罗
定义一堆bean的常用策略是什么,这些bean在开发和生产环境中的使用方式不同?
假设我有2个bean,每个bean实现相同的接口.一个bean用作本地文件系统的抽象,另一个bean连接到分布式文件系统.为了使开发尽可能稳定,开发环境应该使用本地文件系统实现,生产版本使用分布式文件系统bean.
目前我正在做的是有两个xml定义.
native.xml
<bean id="resourceSystem" class="com.cust.NativeResourceSystem" />
Run Code Online (Sandbox Code Playgroud)
distributed.xml
<bean id="resourceSystem" class="com.cust.HadoopResourceSystem">
<constructor-arg name="fs" ref="hdfs" />
</bean>
Run Code Online (Sandbox Code Playgroud)
在创建应用程序上下文时,我省略native.xml或distributed.xml依赖于环境并获取resourceSystembean.
Spring中是否有适当的工具或最佳实践来为不同的环境配置bean定义?
谢谢.