一、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. 【转】Android bluetooth介绍(二): android blueZ蓝牙代码架构及其uart 到rfcomm流程

    原文网址:http://blog.sina.com.cn/s/blog_602c72c50102uzoj.html 关键词:蓝牙blueZ  UART  HCI_UART H4  HCI  L2CAP ...

  2. 数学(容斥计数):LNOI 2016 方

    Description 上帝说,不要圆,要方,于是便有了这道题.由于我们应该方,而且最好能够尽量方,所以上帝派我们来找正方形 上帝把我们派到了一个有N行M列的方格图上,图上一共有(N+1)×(M+1) ...

  3. Nido.Common.Utilities.MD5类

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Sec ...

  4. arcGis引入Dll报无法嵌入互操作类型错误解决方法

    arcGis引入Dll报“无法嵌入互操作类型"ESRI.ARCGIS.Geometry.PointClass".请改用通用接口."   解决方法:设置引用DLL的“嵌入互 ...

  5. Web---字节输出流和字符输出流的共存问题、转发、重定向、请求包含知识点讲解

    本章博客的知识点: 1.字节输出流和字符输出流的共存问题 2.转发时,两个servlet都输出信息的问题 详细知识,见OneServlet和TwoServlet源代码中的注释 转发:传参,访问顺序(d ...

  6. 解popstar

    游戏介绍 http://baike.baidu.com/view/9773832.htm 实现过程: 实现完整的游戏逻辑,包括消除,合并等,也就是实现一个完整的游戏功能. 找出每个连通的星星区域,每个 ...

  7. Eclipse修改字体大小

    1.MyEclipse|Window|General|Appearance|Colors and Fonts->点击Text Font->Edit

  8. QT_校园导航(绘制路线已实现)_Updata_详细注释

    //MainWidget.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include " ...

  9. Unicode与 utf8的互相转换

    <?php function unicode_encode($name) { $name = iconv('UTF-8', 'UCS-2', $name); $len = strlen($nam ...

  10. JMS消息类型模型

    JMS有两种消息类型模型,一种是P2P(Point To Point), 另一种是Pub/Sub(Publisher/Subscriber),二者之间的主要区别在于消息是否支持重复消费. P2P模型中 ...