当前位置:首页>开发>正文

关于Spring读取properties配置文件的一个问题 springboot怎么配置velocity.properties文件

2023-05-20 18:34:31 互联网 未知 开发

 关于Spring读取properties配置文件的一个问题 springboot怎么配置velocity.properties文件

关于Spring读取properties配置文件的一个问题

先将ReadProperties类配置到Spring中去。代码如下
public class ReadProperties{
private String myName
private String myAddress
//为name和address提供GETTER和SETTER方法
public static void main(String[] args){
System.out.println("My name is " myName)
System.out.println("My address is " myAddress)
}
}

然后在applicationContext.xml中进行一些配置将test.properties中的myName和myAddress的值赋给ReadProperties中的name和address代码如下
完整的Spring配置文件如下:

springboot怎么配置velocity.properties文件

一般来说。我们会将一些配置的信息放在。properties文件中。
然后使用${}将配置文件中的信息读取至spring的配置文件。

那么我们如何在spring读取properties文件呢。

1.首先。我们要先在spring配置文件中。定义一个专门读取properties文件的类.
例:
classpath*:jdbc.properties

最新文章