2017-09-16 35 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) 

任何人都可以帮我解决这个问题吗?

回答