@PropertiesSource注解读取配置文件中的数据
来源:互联网 发布:淘宝网店团队人员 编辑:程序博客网 时间:2024/06/05 08:24
task.properties配置文件:
corn=0/1 * * * * ?demo.url=http://www.baidu.comname=job
读取方式:1加载配置文件:@PropertySource(value = "classpath:task.properties")读取:注册bean:@Beanpublic static PropertySourcesPlaceholderConfigurer propertyConfigInDev() { return new PropertySourcesPlaceholderConfigurer();}也可以在xml中<bean>标签注册.@Value(value = "${demo.url}")private String name;读取方式2:加载配置文件:@PropertySource(value = "classpath:task.properties")注入Environment对象@Autowiredprivate Environment environment;通过environment对象获取配置文件中的数据String corn = environment.getProperty("demo.url");这里是我写的一个定时器的Demo:package task;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Lazy;import org.springframework.context.annotation.PropertySource;import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;import org.springframework.core.env.Environment;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Component;/** * Create by szw on 2017/11/23 10:05 */@Component@Lazy(false)@PropertySource(value = "classpath:task.properties")public class SpringTask { @Autowired private Environment environment; @Value(value = "${demo.url}") private String name; @Scheduled(cron = "0/1 * * * * ? ") public void task() { String corn = environment.getProperty("demo.url"); System.out.println("我的名字"+name); System.out.println("我执行了:"+corn); System.out.println("执行"); } @Bean public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() { return new PropertySourcesPlaceholderConfigurer(); }}
阅读全文
0 0
- @PropertiesSource注解读取配置文件中的数据
- 读取配置文件中的数据
- thinkphp读取配置文件中的数据
- 怎么利用Spring利用注解读取配置文件里的数据
- java 读取和写入配置文件中的数据
- springMvc 之 【javaBean读取属性配置文件中的值】---注解方式
- spring提供读取配置文件中的属性注解@Value
- springMvc 如何通过注解@Value 读取配置文件中的内容(.properties)
- 注解+反射+PropertiesProxy 读取配置文件
- springmvc 通过注解读取配置文件
- 扩展spring注解,读取配置文件
- 如何读取配置文件数据
- 读取配置文件数据
- 读取XML配置文件数据
- 读取配置文件中的信息
- 读取jar中的配置文件
- 读取项目中的配置文件
- springMvc 之 【javaBean读取属性配置文件中的值】---非注解方式
- 关于:selenium.common.exceptions.WebDriverException: Message: unknown error: cannot get automation exte
- 第13周项目1-(3)验证二叉排序树相关算法
- 强化学习基础四--Policy Gradient 理论推导
- 学困生别担心,MindManager思维导图来帮你
- ETC+SC挖矿软件-教程Chinaminer公测版,大神检测无抽水
- @PropertiesSource注解读取配置文件中的数据
- spring mvc: The request sent by the client was syntactically incorrect ()
- angularJs添加
- mapreduce系列(3)----在window端远程提交mr程序运行
- 如何打造你的独立观点
- 一日一文(5)
- Host is not allowed to connect to this MySQL server解决方法
- 【Scikit-Learn 中文文档】随机梯度下降
- bzoj1801: [Ahoi2009]chess 中国象棋(Dp)