读取spring加载的properties的值

代码来自网络,测试有效
package com.cqjk.util;  
import java.lang.reflect.Method;
import java.util.Properties;

import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.PropertyResourceConfigurer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.support.PropertiesLoaderSupport;
/**
 * 
 * @author Administrator
* @ClassName: SpringPropertyResourceReader 
* @Description: TODO(获取spring加载的资源文件的属性值) 
* @author A18ccms a18ccms_gmail_com 
* @date 2014-7-7 上午10:04:01
 */
public class SpringPropertyResourceReader {  
    private static ApplicationContext applicationContext=new   
    ClassPathXmlApplicationContext("com/cqjk/config/applicationContext.xml");  
    private static AbstractApplicationContext abstractContext =  
    (AbstractApplicationContext) applicationContext;  
    private static Properties properties=new Properties();  
    static{  
        try{  
            // get the names of BeanFactoryPostProcessor  
            String[] postProcessorNames = abstractContext  
                    .getBeanNamesForType(BeanFactoryPostProcessor.class,true,true);  
              
            for (String ppName : postProcessorNames) {  
                // get the specified BeanFactoryPostProcessor  
                BeanFactoryPostProcessor beanProcessor=  
                (BeanFactoryPostProcessor) abstractContext.getBean(ppName, BeanFactoryPostProcessor.class);  
                // check whether the beanFactoryPostProcessor is   
                // instance of the PropertyResourceConfigurer  
                // if it is yes then do the process otherwise continue  
                if(beanProcessor instanceof PropertyResourceConfigurer){  
                    PropertyResourceConfigurer propertyResourceConfigurer=  
                            (PropertyResourceConfigurer) beanProcessor;  
                      
                    // get the method mergeProperties   
                    // in class PropertiesLoaderSupport  
                    Method mergeProperties=PropertiesLoaderSupport.class.  
                        getDeclaredMethod("mergeProperties");  
                    // get the props  
                    mergeProperties.setAccessible(true);  
                    Properties props=(Properties) mergeProperties.  
                    invoke(propertyResourceConfigurer);  
                      
                    // get the method convertProperties   
                    // in class PropertyResourceConfigurer  
                    Method convertProperties=PropertyResourceConfigurer.class.  
                    getDeclaredMethod("convertProperties", Properties.class);  
                    // convert properties  
                    convertProperties.setAccessible(true);  
                    convertProperties.invoke(propertyResourceConfigurer, props);  
                      
                    properties.putAll(props);  
                }  
            }  
              
        }catch(Exception e){  
            throw new RuntimeException(e);  
        }  
    }  
      
    public static String getProperty(String propertyName){  
        return properties.getProperty(propertyName);  
    }  
}  

 

OMI数据获取与可视化:从下载到大气污染分析 本文详细介绍了如何获取与处理OMI卫星数据,以进行大气污染分析。内容涵盖从NASA GES DISC官方源下载对流层NO2数据、使用MATLAB或Python进行月均数据处理与网格化,到利用m_map或cartopy工具进行专业可视化的完整流程。重点解析了数据下载技巧、NetCDF格式处理、地图投影与填色方法,并探讨了时间序列分析与动态可视化等深度应用,为环境研究者提供了一套从数据到洞察的实用指南。 阅读详情

相关推荐

MATLAB PDE工具箱电磁场仿真平行电容板及电偶极子详解

首先打开matlab,在命令行输入pdetool打开PDE工具箱 工具箱的功能我就不赘述了,大概就是以有限元的数值计算方法,计算二阶偏微分方程,因此可以解决电磁场、热力学等问题。 首先点击左上角按钮,画三个矩形 画完一个后可以双击矩形编辑,参数如下: 其中R1表示上极板,R2表示下极板,R3表示整个空间区域。 在上方Set formula为R3-R2-R1,表示求解区域是整个空间区域减去两个极板。下拉框选择Electrostatics表示求解的是静电场问题。 接下来点击上方菜单栏中的这个按钮,表

weixin_42845306的博客 1万+

spring中properties文件内容解析

applicationContext.xml配置文件 Xml代码   xml version="1.0" encoding="UTF-8"?>  beans xmlns="http://www.springframework.org/schema/beans"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instan

lucky 1242

Python与numpy版本兼容性排查指南

本文详细解析了Python与numpy版本兼容性问题,提供了快速诊断和解决版本冲突的实用方法。通过查看版本信息、使用官方兼容性对照表以及降级或升级环境等方案,帮助开发者有效避免常见的报错问题,如'ImportError'和'AttributeError'。文章还介绍了使用虚拟环境和requirements.txt等工程实践,确保项目依赖的稳定性。

weixin_29089057的博客 319

Spring加载properties文件的两种方式

我的个人博客站点:http://www.itcodai.com         在项目中如果有些参数经常需要修改,或者后期可能需要修改,那我们最好把这些参数放到properties文件中,源代码中读取properties里面的配置,这样后期只需要改动properties文件即可,不需要修改源代码,这样更加方便。在Spring中也可以这么做,而且Spring有两种加载properties文件的方式...

18万+

常见消息队列:ActiveMQ、RabbitMQ、RocketMQ、Kafka的区别总结

常见消息队列:ActiveMQ、RabbitMQ、RocketMQ、Kafka的区别。

qq_30713721的博客 3471

企业级防火墙实战:用深信服AF8.0打造安全办公网络(含流控/僵尸防护配置)

本文详细介绍了如何利用深信服AF8.0防火墙构建企业级安全办公网络,涵盖设备初始化、多接入方式配置、三维一体安全防护体系(包括应用控制、僵尸防护和智能流控)以及典型问题排查。通过实战案例和配置模板,帮助IT管理员高效部署和优化网络安全管理,提升企业网络安全防护能力。

weixin_28716443的博客 281

Spring加载Properties配置文件,java通过注解读取数据

1、用法示例: 在springMVC.xml配置文件中添加标签 (推荐用这个,这个用的比较多,也比较简洁) <context:property-placeholder location="classpath:salesman.properties"/> 加载多个 <context:property-placeholder location="classpat...

苏凯的博客 3万+

国产麒麟系统PXE安装-UEFI引导

注意: 适用uefi引导 适用x86_64架构 一键部署脚本扣我 1.上传ISO到PXE服务器,拷贝ISO文件 # mkdir /kylin_iso # mount -o loop Kylin-Server-10-SP1-Release-Build04-20200711-x86_64.iso /kylin_iso/ 2.配置http,获取安装源 # yum -y install httpd # mkdir /var/www/html/{ks,kylin} # 注意一定是"/kylin_iso/

河静 5053

五种方式让你在java中读取properties文件内容不再是难题

一、背景   最近,在项目开发的过程中,遇到需要在properties文件中定义一些自定义的变量,以供java程序动态的读取,修改变量,不再需要修改代码的问题。就借此机会把Spring+SpringMVC+Mybatis整合开发的项目中通过java程序读取properties文件内容的方式进行了梳理和分析,现和大家共享。 二、项目环境介绍     Spring 4.2.6.RELE...

Realize My Dream 7221

ShengBTE热导计算:利用ShengBTE计算热导显示NAN的原因是什么?算出的热导不随平均声子自由程变化

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值 。

**My Coding Family** 963

《Python入门到精通》函数详解

函数就是一段「封装」起来的「代码」,目的是提高代码的「模块性」和「复用性」。 2、函数的参数 2.1、变量的就近原则 2.2、传递参数 2.3、形参和实参 2.4、位置参数 2.5、缺省参数 2.6、可变类型和不可变类型 2.7、关键字参数 3、匿名函数 4、函数的返回值

wangyuxiang946的博客 1万+

spring加载外部properties文件属性时,读取到userName变量值和properties文件的值不一致

摘要:Spring属性注入时,${userName}读取到系统环境变量而非properties文件值,原因是系统变量优先级更高。解决方案:1)重命名属性(如改为db.userName)避免冲突;2)Spring 4.3+可通过配置PropertySourcesPlaceholderConfigurer,设置localOverride=true并确保其作为首个bean定义,强制本地属性覆盖系统变量。注意BeanFactoryPostProcessor的执行顺序会影响配置效果。(149字)

纳兰青华的博客 410

手把手教你学Simulink——机器人控制场景实例:基于Simulink的双足人形机器人步态生成与ZMP稳定控制仿真

ZMP是地面上合力矩在水平方向为零的点。对于平面行走: [ x_{\text{zmp}} = x_c - \frac{z_c}{g} \ddot{x}_c ]📌稳定性判据ZMP必须始终位于支撑脚的凸包(即脚掌范围内)本文完成了基于Simulink的双足人形机器人ZMP稳定控制仿真,实现了:✅ 基于LIPM生成稳定CoM轨迹✅ 构建ZMP参考与验证机制✅ 设计简化踝关节PD控制器✅ 验证ZMP始终位于支撑脚内 → 动态平衡✅ 为人形机器人步态规划奠定理论基础。

MHD0815的博客 138

java properties读取缓存_利用Java注解特性加载属性文件(properties)的值到Java类 spring java propertyplaceholderconfigurer p...

利用Java注解特性加载属性文件(properties)的值到Java类 spring java propertyplaceholderconfigurer properties springSpring提供一个PropertyPlaceholderConfigurer类,可以读取配置文件,然后在Spring配置文件通过${Hibernate.dialect}这种方式注入到JavaBean中,有个...

weixin_42506647的博客 162

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

spring使用<context:property-placeholder>属性加载properties文件而用@Value标签读取properties文件的值导致的中文乱码问题

参考博客:https://blog.youkuaiyun.com/j3oker/article/details/53839210 在SSM项目中使用<context:property-placeholder>标签来加载properties配置文件 然后通过@Value标签来获取配置文件中的值 但是确是中文乱码 解决方法是在<context:property-placeholder>标签上配置file-encoding="UTF-8"属性。 中文乱码问题得以解决 ..

二木成林 679

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

spring容器读取properties文件,并得到其中配置的值

spring容器读取properties文件,并得到其中配置的值

LoveQHH的博客 1288

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

properties java读取_Java读取properties的几种实现方式

1.通过java.util.Properties.Properties类读取配置信息Properties类继承自Hashtable类并且实现了Map接口,也是使用一种键值对的形式来保存属性集。不过Properties有特殊的地方,就是它的键和值都是字符串类型。加载属性文件,它提供了两个方法:load和loadFromXMLload有两个方法的重载:load(InputStream inStream...

weixin_39950552的博客 312

spring中加载properties文件

spring中加载properties文件 在src下新建一个properties文件,在spring配置文件中引入xmlns:context添加 <context:property-placeholder location="classpath:db.properties"/> 添加属性文件记载,并且在中开启自动注入需要注意 SqlSessionFactoryBean的id不能叫做...

weixin_44007988的博客 223

Spring和Spring boot项目中拿*.properties中的常量值

1、Spring Boot项目中(1)在Spring Boot项目的根配置文件application.properties中添加数据,如下                    com.test.user=facebook                    com.test.password=654321(2)用到这两个值的地方,使用@Value注解直接取值,如下               ...

洋成林 7391

Spring读取properties文件

假设此时有properties文件:mytest.properties testKey=testValue 1 利用PropertyPlaceholderConfigurer 1.1 注解 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:mytest.properties"

积 1639

读取配置properties的key值

Properties prop = new Properties(); InputStream in = this.getClass().getResourceAsStream("/public_system.properties"); String goodsNum = ""; try { ...

611

Spring中配置和读取多个Properties文件

Spring中配置和读取多个Properties文件 (2013-09-04 16:11:01) 转载▼   分类: web 一个系统中通常会存在如下一些以Properties形式存在的配置文件 1.数据库配置文件demo-db.properties: Properties代码   database.url=jdbc:mysql://lo

Coder Ben 721

通过@Value注解读取.properties配置内容

@Value注解读取properties文件中的配置信息

nylic的博客 1124

spring mvc controller中获取属性文件(properties)的值

1.将properties文件位置加到spring mvc的配置的文件(spring-mvc.xml)中,如下 2.http.properties配置文件 http.url=192.168.1.10 http.port=8086 3.Controller代码 @Value("${http.url}") private String strUrl; @

删去昨天的专栏 9749

Get value from properties file outside a jar using Spring

I have a jar file which need to dynamically load external properties file and read values from this properties file. Those values are needed in the java program. With Spring, it's very easy to do that

smile_juan 1495
上一篇: memcached简介及java使用方法(转)
下一篇: webservice连接超时 读取信息超时设置
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值