【发布时间】:2012-05-06 04:38:39
【问题描述】:
我想从 WEb.XML 中删除 env-entry
<env-entry>
<description>String used in masking process</description>
<env-entry-name>default_mask</env-entry-name>
<env-entry-value>*</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
所以我创建了一个包含 (c:/my.properties) 的属性文件
default_mask=9999
所以我尝试使用现有的解决方案,如 JndiPropertyPlaceholderConfigurer(来自 Spring Jndi Context and PropertyPlaceholderConfigurer ) 并在spring的applicationcontext.xml中配置为
<bean
class="com.test.webappl.JndiPropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="location" value="file:c:\my.properties"/>
启动Tomcat服务器读取属性文件的样子
.......com.test.webappl.JndiPropertyPlaceholderConfigurer] Loading properties file from URL [file:c:/my.properties]
当我阅读时现在在 java 中
Context context = new InitialContext();
String resource = context.lookup("java:comp/env/default_mask");
应用程序抛出以下错误
**javax.naming.NameNotFoundException: Name default_mask is not bound in this Context**
我在 web.xml 中的 spring 设置也是
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationcontext.xml</param-value>
</context-param>
有人知道我使用的方法是否正确吗? 我知道这已经在Spring Jndi Context and PropertyPlaceholderConfigurer 中得到了回答,但不知何故不适用于我的情况
提前致谢
【问题讨论】:
标签: java spring properties jndi