我需要导入Spring属性(在Spring Boot中)作为spring.datasource,server.port...来自位于文件系统中的文件(在java应用程序之外)。
这适用于需要连接到数据库的Spring Boot应用程序。
spring:
datasource:
url: jdbc:oracle:thin:@X.X.X.X:XXXX:XXXX
username: XX
password: XX
driver-class-name: oracle.jdbc.driver.OracleDriver
hikari:
connection-timeout: 60000
maximum-pool-size: 5
application:
name: XX
server:
port: 9000
contextPath: /
servlet:
session:
cookie:
http-only: true
secure: true到目前为止,我还不能在类中使用@PropertySource(value = "C:/test.properties")从文件导入属性。
发布于 2019-04-12 16:18:41
有多种方法可以实现这一点。我更喜欢的是用@PropertySource注释你的应用程序主类,并配置它来读取你的属性文件。
示例:
@SpringBootApplication
@PropertySource({
"file:C:\test.properties"
})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}https://stackoverflow.com/questions/55647090
复制相似问题