【发布时间】:2013-01-12 06:57:21
【问题描述】:
在发布这个问题之前,我谷歌从 Spring 项目(它不是基于 Web 的项目)中获取属性。我很困惑,因为每个人都在谈论 application-context.xml 并且有类似的配置
但是,我正在使用 Spring 开发普通的 Java 项目(没有 Web 应用程序和类似的东西)。但我想从属性文件中获取一些需要在 JAVA 文件中使用的通用属性。如何使用 Spring/Spring Annotations 实现这一点?
我的项目下应该在哪里配置myprops.properties文件以及如何通过spring调用?
我的理解是 application-context.xml 仅用于基于 Web 的项目。如果没有,我应该如何配置这个 application-context.xml,因为我没有 web.xml 来定义 application-context.xml
【问题讨论】:
-
你如何定义你的 Spring 上下文?每个 Spring 应用程序都有一个 Spring 上下文。
-
XML 配置不仅适用于基于 Web 的项目
-
是的。你是对的。我的问题是该 XML 文件需要放在 Java 项目中的项目工作区(spring.xml 或 other.xml)下的确切位置
标签: java spring properties spring-annotations