zoukankan      html  css  js  c++  java
  • spring 注解使用小技巧

    在spring 3.0中,可以通过使用@value,对一些如xxx.properties文件
    中的变量,进行键值对的注入
     
    例如:
     
    1 首先在applicationContext.xml中加入:
       <beans xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
    </beans>
       的命名空间,然后
     
    2
    <util:properties id="settings" location="WEB-INF/classes/META-INF/spring/test.properties" />
     
    3 创建test.properties
       abc=123
     
    4
    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中了。
  • 相关阅读:
    Matplotlib.pyplot 三维绘图
    Matplotlib.pyplot 二维绘图
    面对对象进阶
    面对对象基础
    python安装第三方模块
    json & pickle
    os模块
    sys模块
    正则表达式
    Python2与Python3的编码差异
  • 原文地址:https://www.cnblogs.com/yanzhenxing/p/3083157.html
Copyright © 2011-2022 走看看