写定时任务的参考代码
来源:互联网 发布:文化自信 知乎 编辑:程序博客网 时间:2024/06/05 18:23
值得注意的是使用el表达式的时候一定要先注册类PropertySourcesPlaceholderConfigurer:可以用@Bean注册或者用XML的<bean>标签
这里贴上源码:
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 = "${corn}") 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
- 写定时任务的参考代码
- 自己写的定时任务管理器
- 如何写mysql的定时任务
- drupal 写定时任务
- linux写定时任务
- Quarz写定时任务
- Spring的定时任务的代码实例
- java定时处理任务的代码
- 调用定时任务的配置和代码
- 用C#写的俄罗斯方块代码参考
- 通过监听器写的后台运行的定时任务
- Oracle中写定时任务
- laravel定时任务怎么写
- Python 学习:今天写了一个简单的定时任务
- android uiautomator如何写一个定时任务的方法
- 在web端写定时任务的方式
- 使用navicat for mysql 写一个简单的定时任务。
- 嵌入式启动定时任务代码
- 自定义注解校验器
- scala编程04--数组
- 第十二周 Prim算法的验证
- Nginx浏览器缓存设置
- OkHtttp拦截器
- 写定时任务的参考代码
- Shiro入门学习三
- JSP
- ETH挖矿工具之长沙矿工
- HTML5 canvas 绘制简单logo
- 【Scikit-Learn 中文文档】十五:特征选择
- zookeeper移除及升级
- 关于A53开发板启动问题
- 第13周项目2-二叉树排序树中查找的路径