简体   繁体   English

如何在文件系统中使用Spring框架加载属性文件

[英]How to load properties file using spring framework in file system

Now I'm trying to load properties file in computer file system in my desktop application using spring framework. 现在,我尝试使用Spring框架在桌面应用程序的计算机文件系统中加载属性文件。 configuration folder have two files: datasource-tx-jpa.xml and database.properties (both files locate at same folder). 配置文件夹有两个文件: datasource-tx-jpa.xmldatabase.properties (两个文件都位于同一文件夹中)。 But when I run this application then a message box appear with message can not load ${sqlserver.jdbc.driverClassName} in dataSource . 但是,当我运行此应用程序时,出现一个消息框,提示消息can not load ${sqlserver.jdbc.driverClassName} in dataSource Below is configuration of datasource-tx-jpa.xml . 以下是datasource-tx-jpa.xml配置。

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

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">

    <property name="driverClassName" value="${sqlserver.jdbc.driverClassName}" />
    <property name="url" value="${sqlserver.jdbc.url}" />
    <property name="username" value="${sqlserver.jdbc.username}" />
    <property name="password" value="${sqlserver.jdbc.password}" />
</bean>

由于该文件位于资源文件夹中,因此可以使用<context:property-placeholder location="classpath*:database.properties" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM