2017-09-16 33 views
0

我想要獲取屬性文件的值,如下所示: - 屬性文件的名稱是application.properties,值如下所示: -如何在Spring中從屬性文件獲取值

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) 

任何人都可以幫我解決這個問題嗎?

回答