一、1.占位符的应用:(@Autowired注解方式,不需要建立set与get方法了,xml注入也不需要写了)

http://www.cnblogs.com/susuyu/archive/2012/09/10/2678458.html

二、

2、java方式访问(已经验证过好用)

1、通过spring配置properties文件

[java]  <bean id="propertyConfigurer"      class="com.tjsoft.base.util.CustomizedPropertyPlaceholderConfigurer">      <property name="ignoreResourceNotFound" value="true" />      <property name="locations">          <list>              <value>/WEB-INF/config/jdbc.properties</value>              <value>/WEB-INF/config/mail.properties</value>              <value>/WEB-INF/config/system.properties</value>          </list>      </property>  </bean>

其中class为自己定义的类

2、自定义类CustomizedPropertyPlaceholderConfigurer

[java]  import java.util.HashMap;  import java.util.Map;  import java.util.Properties;    import org.springframework.beans.BeansException;  import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;  import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;    /**  * 自定义PropertyPlaceholderConfigurer返回properties内容  *   * @author LHY 2012-02-24  *   */  public class CustomizedPropertyPlaceholderConfigurer extends          PropertyPlaceholderConfigurer {        private static Map<String, Object> ctxPropertiesMap;        @Override      protected void processProperties(              ConfigurableListableBeanFactory beanFactoryToProcess,              Properties props) throws BeansException {          super.processProperties(beanFactoryToProcess, props);          ctxPropertiesMap = new HashMap<String, Object>();          for (Object key : props.keySet()) {              String keyStr = key.toString();              String value = props.getProperty(keyStr);              ctxPropertiesMap.put(keyStr, value);          }   www.2cto.com     }        public static Object getContextProperty(String name) {          return ctxPropertiesMap.get(name);      }    }

这样就可以通过CustomizedPropertyPlaceholderConfigurer类来获取properties属性文件中的内容了

3、如何获取属性文件的内容

String host =  (String) CustomizedPropertyPlaceholderConfigurer.getContextProperty("mail.smtp.host");

三、未验证,不知道好用不

action也是spring配置的bean吗?
是的话,直接注入就行了。
<bean id="actionname" class="com.MyAction">
   <property name="property1" value="${configed.property1}"/>
</bean>

如果不是,可以将这个property注入到System.properties中去
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
    depends-on="PlaceholderConfigurer">
<property name="targetClass">
<value>java.lang.System</value>
</property>
<property name="targetMethod">
<value>setProperty</value>
</property>
<property name="arguments">
<list>
<value>property1</value>
<value>${configed.property1}"</value>
</list>
</property>
</bean
然后在action中使用System.getProperty("property1")

spring 的 PropertyPlaceholderConfigurer读取的属性怎么访问 (java访问方式,不是xml中的占位符哦)及此类的应用的更多相关文章

  1. Spring属性占位符 PropertyPlaceholderConfigurer

    http://www.cnblogs.com/yl2755/archive/2012/05/06/2486752.html PropertyPlaceholderConfigurer是个bean工厂后 ...

  2. mybatis与spring整合时读取properties问题的解决

    在学习mybatis与spring整合是,想从外部引用一个db.properties数据库配置文件,在配置文件中使用占位符进行引用,如下: <context:property-placehold ...

  3. Android (cocos2dx 网络访问)访问权限设置

    Android开发应用程序时,如果应用程序需要访问网络权限,需要在 AndroidManifest.xml 中加入以下代码: 同样的如果用到其它的权限,也需要作出声明,部分权限列表如下: androi ...

  4. Spring拓展接口之BeanFactoryPostProcessor,占位符与敏感信息解密原理

    前言 开心一刻 一只被二哈带偏了的柴犬,我只想弄死隔壁的二哈 what:是什么 BeanFactoryPostProcessor接口很简单,只包含一个方法 /** * 通过BeanFactoryPos ...

  5. Spring PropertyResolver 占位符解析(一)API 介绍

    Spring PropertyResolver 占位符解析(一)API 介绍 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html ...

  6. Spring中手动增加配置文件中占位符引用的变量

    在项目中遇到一个这样的需求,项目的配置文件由外部传入,这时spring配置文件那些占位符变量该如何取值呢? 解决这个问题的做法有几种,我想到的大概有以下三种: 1.通过系统属性来实现,把外部传入的配置 ...

  7. Spring Cloud Finchley.SR1 版本的坑:placeholer占位符无法解析!

    接入nacos 之后,想把所有的配置丢上去. 启动程序是: @EnableDiscoveryClient @RestController @ComponentScan(basePackages = { ...

  8. SPRING多个占位符配置文件解析源码研究--转

    原文地址:http://www.cnphp6.com/archives/85639 Spring配置文件: <context:property-placeholder location=&quo ...

  9. spring占位符解析器---PropertyPlaceholderHelper

    一.PropertyPlaceholderHelper 职责 扮演者占位符解析器的角色,专门用来负责解析路劲中or名字中的占位符的字符,并替换上具体的值 二.例子 public class Prope ...

随机推荐

  1. SharePoint 2010 母版页定制小思路介绍

    转:http://tech.ddvip.com/2013-11/1384521515206064.html 介绍:我们使用SharePoint2010做门户网站,经常需要定制母版页,但是2010提供的 ...

  2. js前台与后台数据交互-前台调后台

    转自:http://blog.csdn.net/wang379275614/article/details/17033981   网站是围绕数据库来编程的,以数据库中的数据为中心,通过后台来操作这些数 ...

  3. POJ 3107

    #include<iostream> #include<cstdio> #include<cstring> #include<string> #incl ...

  4. IIS 7.0, ASP.NET, pipelines, modules, handlers, and preconditions

    1.0 What is the IIS Pipeline Conceptually, the IIS pipeline is a state machine with the following st ...

  5. Lua 中使用面向对象(续)

    上一篇文章给了一个面向对象的方案,美中不足的是没有析构函数 Destructor,那么这一次就给它加上. 既然是析构,那么就是在对象被销毁之前做该做的事情,lua 5.1 的 userdata 可以给 ...

  6. Mac下快捷键列表

    主界面 command + tab 切换程序 command + ` 在程序内切换界面 command + w 关闭界面 command + q 关闭程序 command + option + esc ...

  7. GCC基本知识

    掌握下面的对GCC会有一个比较清晰的大致的了解: 不经意间,GCC已发展到了4.3的版本,尽管在软件开发社区之外乏人闻问,但因为GCC在几乎所有开源软件和自由软件中都会用到,因此它的编译性能的涨落会直 ...

  8. Jsp_demo:自定义标签

    Jsp自定义标签: 1.继承SimpleTagSupport,重写doTag(). 2.在WEB-INF/ 下配置**.tld文件 3.Jsp页面引入自定义标签:<%@ taglib uri=& ...

  9. Tornado自定义分布式session框架

    一.session框架处理请求执行的流程: 1.服务器端生成随机的cookie字符串 2.浏览器发送请求,服务器将cookie返回给浏览器. 3.服务器在生成一个字典.字典的key为cookie,va ...

  10. 获取自身ip

    curl http://members.3322.org/dyndns/getip curl一下这个网址即可 Linux 终端中可以直接这样使用