Spring3 的 @value

阅读更多

在spring 3.0中,可以通过使用@value,对一些如xxx.properties文件 
中的文件,进行键值对的注入,例子如下:

 

1 首先在applicationContext.xml中加入: 

 

  

  

 
  

 

 

3 创建test.properties 
   abc=123 

 

 

import org.springframework.beans.factory.annotation.Value;   
import org.springframework.stereotype.Controller;   
import org.springframework.web.bind.annotation.RequestMapping;   
  
@RequestMapping("/admin/images")   
@Controller   
public class ImageAdminController {   
  
    private String imageDir;   
           @Value("#{settings['test.abc']}")   
    public void setImageDir(String val) {   
        this.imageDir = val;   
    }   
}  

 

这样就将test.abc的值注入了imageDir中

 

 

你可能感兴趣的:(spring)