spring的好处--PropertyPlaceholderConfigurer
来源:互联网 发布:ios看杂志软件 编辑:程序博客网 时间:2024/04/25 07:12
我的程序终于又进展了,基本功能已经实现了,开始开发WEB界面了。这是却出现了一个问题。原先的Encoder需要指定一个配置文件目录,然后将这个目录下的所有文件读入。
<bean id="encoder" class="test.Encoder" init-method="init">
<property name="resourceDirectory"><value>WEB-INF/lib/wbxml</value></property>
</bean>
当在命令行下调试时他工作的很好,但是当在tomcat下运行时却报告说找不到该目录。这是当然,因为tomcat下相对目录不在正确。通常情况下的解决办法是用ServletContext.getRealPath得到绝对路径。这是这样Encoder却额外的需要增加对ServletContext的依赖,这是我所不愿意看到的。
幸好发现了PropertyPlaceholderConfigurer,最后的解决方案是
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
<bean id="encoder" class="test.Encoder" init-method="init">
<property name="resourceDirectory"><value>${webapp.root}/WEB-INF/lib/wbxml</value></property>
</bean>
原来PropertyPlaceholderConfigurer可以将${...}替换为指定的properties文件或system properties中的值,而spring在Log4jConfigListener或是WebAppRootListener会指定一个system property表示web root的值,default是webapp.root。
不幸的是目前spring1.0.2似乎有一个BUG,PropertyPlaceholderConfigurer不能正确地工作在Inner Bean中,我已提交了这个问题,希望很快能解决。
- spring的好处--PropertyPlaceholderConfigurer
- spring的好处--PropertyPlaceholderConfigurer
- spring的 PropertyPlaceholderConfigurer配置
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer
- Spring PropertyPlaceholderConfigurer的使用
- Spring PropertyPlaceholderConfigurer的使用
- spring propertyplaceholderconfigurer的使用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer使用
- Spring:PropertyPlaceholderConfigurer的使用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- 游戏_猜数字
- 简析二战德国1944东线战略
- Java反射机制
- Visual C++实现图形特技
- 游戏_石头,剪刀,布
- spring的好处--PropertyPlaceholderConfigurer
- typedef的四个用途和两个陷阱
- java.lang.IllegalStateException: Cannot forward after response has been committed异常
- MFC的关键技术:动态创建
- hibernate中的异常
- 页面跳转的几种方式
- Windows动态库与Linux共享对象
- 在MFC下实现图像放大镜
- 在MFC下如何定义全局变量和全局函数