spring读取properties文件

lizhongyi188 2011-04-26 11:31:42
如结构:
proName
src
applicationContext.xml

config
config.properties

在applicationContext中怎么加载不是在src目下的配置文件,config在这里只是一个文件夹
...全文
192 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yingzhuo2011 2011-04-26
  • 打赏
  • 举报
回复
误点了发帖,蛋疼。
我上面的帖子请忽略。

2.5.6

<bean id="placeHolder"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:config/config.properties</value>
</list>
</property>
</bean>


3.0.5

<context:property-placeholder location="file:config/file.properties" />

yingzhuo2011 2011-04-26
  • 打赏
  • 举报
回复
spring 3.x
<context:property-placeholder location="classpath*:config/*.properties" />

spring 2.5.x
<bean id="placeHolder"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/config.properties</value>
</list>
</property>
</bean>
magicluo 2011-04-26
  • 打赏
  • 举报
回复
xml中配置


<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config.properties</value>
</list>
</property>
</bean>



lizhongyi188 2011-04-26
  • 打赏
  • 举报
回复
coooliang 2011-04-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 yingzhuo2011 的回复:]
误点了发帖,蛋疼。
我上面的帖子请忽略。

2.5.6

XML code

<bean id="placeHolder"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
……
[/Quote]

+1
shine333 2011-04-26
  • 打赏
  • 举报
回复
ls是一种做法,不过还有一种更通用的做法,不仅针对spring。即程序需要读取的资源,不在默认的src(其实是classpath下)
如果不是特意把放到classpath外面去的话,可以在工程中,把config也设置为src目录,或者在jvm中添加classpath,指向config目录。

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧