spring 3中新增的@value注解

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

首先在applicationContext.xml中加入:
  


的命名空间,然后



创建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 3中新增的@value注解)