xml之xmlns 以及spring task
来源:互联网 发布:大数据的优势与劣势 编辑:程序博客网 时间:2024/06/06 18:27
估计有人会和我产生同样的问题,xml配置文件开始部分第一个bean 里面的内容不是很懂,但是基本的使用应该是没有什么问题的,感兴趣的同学会去google,百度下,记录下来 我只是其中一个。旨在自己谨记,观者分享。
始由
http://www.w3school.com.cn/xml/xml_namespaces.asp xml 命名空间的讲解这里已经表明,不做过多赘述。
看下我们经常会看到的配置
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd " default-autowire="byName" default-lazy-init="false">
上面是我们项目的xml 配置命名空间
其中bean,context,aop,tx,task 都是spring最熟悉不过的的。
如果你要想使用xml配置某个标签你就要去添加相对应的 xmlns ,xml解析就会根据相应的规则去做判断
demo
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation=”http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd ”
这个是task xmlns 其中xmlns:task “task” 是定义的标签名称 ,你可以直接访问 这个
url “http://www.springframework.org/schema/task” 你会发现这个对应的“房子”你就到了spring task 的“家”了,而相应的规则 就是里面具体的 定义规则。
<task:annotation-driven/>
Element : annotation-driven
Enables the detection of @Async and @Scheduled annotations on any Spring-managed object. If
present, a proxy will be generated for executing the annotated methods asynchronously. See Javadoc
for the org.springframework.scheduling.annotation.EnableAsync and
org.springframework.scheduling.annotation.EnableScheduling annotations for information on code-
based alternatives to this XML element.
启用相应的注解
代码里面你可以这样 写下
`
import java.io.IOException;
import java.util.Date;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.alibaba.dubbo.common.json.JSON;
import com.tf56.ps.dao.MyTaskService;
import com.tf56.ps.entity.AdsManage;
@Component
public class MyTaskServiceImpl implements MyTaskService {
//涉及到cron 表达式 http://cron.qqe2.com///5s @Scheduled(cron="0/5 * * * * ? ")@Overridepublic void SysWork() { System.err.println("--------------------- SysWork mytask begin------------------");}@Scheduled(cron="0/7 * * * * ? ")@Overridepublic void DoWork() { System.err.println("--------------------- DoWork mytask begin------------------"); }
}
`
以上你可能已经实现了基于注解的spring task 配置 。
反例 非基于注解实现task 配置 较多可能涉及task 具体代码解读稍后奉上。
cron 表达式 http://cron.qqe2.com/ 没做过深入解读
本篇基于 xml命名空间探索引申到task 注解配置 菜鸟奉上 欢迎交流
- xml之xmlns 以及spring task
- xml解析错误之xmlns
- Spring配置文件(xml)中的xmlns解析
- Spring application-context.xml 的 xmlns配置
- XML之命名空间的作用(xmlns)
- XML之命名空间的作用(xmlns)
- XML之命名空间的作用(xmlns)
- XML之命名空间的作用(xmlns)
- XML之命名空间的作用(xmlns)
- Springmvc之task.xml
- 关于spring xml文件中的xmlns,xsi:schemaLocation
- spring xml头文件xmlns和xsi的意思
- xmlns spring application.xml 头文件的透彻理解
- 学spring之xmlns配置之命名空间
- spring-guide之scheduled-task
- spring task 注解+xml的demo
- spring task 注解+xml的demo
- 有关xml中的xmlns
- css全局样式表
- Python起步之异常处理
- MFC中获取HRESULT错误消息内容
- DFS——深度优先算法(Depth First Search)
- HDU 5938 Four Operations(枚举)
- xml之xmlns 以及spring task
- Codeforces Round #420 A. Okabe and Future Gadget Laboratory
- Miss晒美照:这是个怎样的女孩?粉丝疯狂开车很扎心
- java8数值流与对象流的相互转换
- 汇编-x86指令查看
- ue4 please recompile with a command line option of '-Zm111' or greater
- Java Web入门
- SOAPUI中文教程---使用断言
- php中创建和调用webservice接口示例