我正在尝试执行以下操作: - 使用值 'us' 配置 JNDI env-entry 'country' - 让 Spring 读出 env-entry 'country' - 在 Spring EL 中使用它来加载配置文件
所以我的 applicationContext 会是这样的:
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:application-${country}.properties</value>
</list>
</property>
</bean>
问题是:如何将 JNDI 中的值 'java:comp/env/country' 转换为 ${country}?
这不起作用:
<jee:jndi-lookup id="country" jndi-name="java:comp/env/country"/>
*编辑*
我已经添加<context:property-placeholder/>
并且日志显示它找到了 JNDI 名称,但它仍然拒绝使用它。日志:
PropertySourcesPropertyResolver | Searching for key 'country' in [jndiProperties]
JndiTemplate | Looking up JNDI object with name [java:comp/env/country]
JndiLocatorDelegate | Located object with JNDI name [java:comp/env/country]
JndiPropertySource | JNDI lookup for name [country] returned: [us]
PropertySourcesPropertyResolver | Found key 'country' in [jndiProperties] with type [String] and value 'us'
...
Could not resolve placeholder 'country' in string value "classpath*:application-${country}.properties
这真是令人沮丧……