以下資源前綴始終是有效的:
表4.1。資源字符串
Prefix Example Explanation
---------------------------------------------------------------------------
classpath: | classpath:com/myapp/config.xml | Loaded from the classpath.
file: | file:/data/config.xml | Loaded as a URL, from the
| | filesystem. [1]
http: | http://myserver/logo.png | Loaded as a URL.
(none) | /data/config.xml | Depends on the underlying
| | ApplicationContext.
[1]但也見Section 4.7.3, 「FileSystemResource caveats」。
來源:Spring Reference > The ResourceLoader
但我實在不明白相對路徑如何適合在那裏。也許你應該詳細說明你的要求。
感謝您的其他信息。你是對的,它不能在這種情況下工作
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="org.h2.Driver"
p:url="jdbc:h2:~/mydb;AUTO_SERVER=TRUE"
p:username=""
p:password="" />
Spring從不分析JDBC URL,它只是將它傳遞給bean。什麼我建議是使用the PropertyPlaceHolderConfigurer
mechanism:
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="org.h2.Driver"
p:url="jdbc:h2:${dbpath};AUTO_SERVER=TRUE"
p:username=""
p:password="" />
<!-- example config -->
<context:property-placeholder location="classpath:com/foo/jdbc.properties"
systemPropertiesMode="override" />
現在,您可以配置路徑在屬性上的類路徑或每個系統屬性文件。其實,你可能想要做這樣的事情(使整個URL配置,而不僅僅是DB模式名):
p:url="${dbpath}"
@skaffma:現在用一個例子更新。 – Oliver 2011-03-22 14:00:11
我有同樣的要求。任何想法這個要求? – Trung 2014-01-10 02:41:16