我想获取属性文件的值,如下所示: - 属性文件的名称是 application.properties ,值如下: -
config.name=abcd
config.pwd=efgh
我将检索值的代码如下: -
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@PropertySource("classpath:application.properties")
public class CustomerService {
@Value("${config.name}")
private String name;
@Value("$(config.pwd)")
private String data;
System.out.println("name is ::" +name);
System.out.println("data is ::" +data);
}
但是当代码返回时,输出将以
的形式出现name is ::ankita
data is ::$(config.pwd)
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
尝试使用:@Value("${config.pwd}")