学习记录(spring quartz定时任务配置文件+Jsoup)
2016-09-18 17:01
573 查看
个人学习记录,如果有哪里不对的地方请告诉我,谢谢了!
1. spring quartz定时任务完整配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="false">
<bean id="quartzJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="需要进行定时任务的类"/>
<property name="targetMethod" value="需要进行定时任务的方法"/>
<property name="concurrent" value="false"/> <!--设置为false的意思是当有多个任务执行的时候,会依次执行 -->
</bean>
<bean id="quartzTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail">
<ref bean="quartzJob" />
</property>
<property name="startDelay">
<!-- 服务启动后延时10s开始计时任务 -->
<value>10000</value>
</property>
<property name="repeatInterval">
<!-- 每隔60秒重试一次同步 -->
<value>60000</value>
</property>
</bean>
<!--第三步 启动定时任务,注意这里的ref bean -->
<bean id="quartzSchedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy">
<property name="triggers">
<list>
<ref bean="quartzTrigger"></ref>
</list>
</property>
</bean>
</beans>
2. jsoup+httpClient
httpClient来抓取页面,jsoup来对html页面进行分析,获取数据,jsoup初次使用
Document document = Jsoup.parse("通过httpClient获取到的String类型的页面");//转化为可以让jsoup操作的[b]Document
[/b]
Elements list = document.getElementsByAttributeValue("xxx", "xxx");//根据标签里的属性的值来获得标签元素的集合
for (Element element : [b]list
) {
String text= element.childNodes().get(0).toString();//获得该标签下第一个子标签的内容
}[/b]
document.select("meta[itemprop=image]").get(0).attr("content");//获得meta标签中
[b]itemprop=image的标签中第一个的 content属性的值
[/b]
1. spring quartz定时任务完整配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="false">
<bean id="quartzJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="需要进行定时任务的类"/>
<property name="targetMethod" value="需要进行定时任务的方法"/>
<property name="concurrent" value="false"/> <!--设置为false的意思是当有多个任务执行的时候,会依次执行 -->
</bean>
<bean id="quartzTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail">
<ref bean="quartzJob" />
</property>
<property name="startDelay">
<!-- 服务启动后延时10s开始计时任务 -->
<value>10000</value>
</property>
<property name="repeatInterval">
<!-- 每隔60秒重试一次同步 -->
<value>60000</value>
</property>
</bean>
<!--第三步 启动定时任务,注意这里的ref bean -->
<bean id="quartzSchedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy">
<property name="triggers">
<list>
<ref bean="quartzTrigger"></ref>
</list>
</property>
</bean>
</beans>
2. jsoup+httpClient
httpClient来抓取页面,jsoup来对html页面进行分析,获取数据,jsoup初次使用
Document document = Jsoup.parse("通过httpClient获取到的String类型的页面");//转化为可以让jsoup操作的[b]Document
[/b]
Elements list = document.getElementsByAttributeValue("xxx", "xxx");//根据标签里的属性的值来获得标签元素的集合
for (Element element : [b]list
) {
String text= element.childNodes().get(0).toString();//获得该标签下第一个子标签的内容
}[/b]
document.select("meta[itemprop=image]").get(0).attr("content");//获得meta标签中
[b]itemprop=image的标签中第一个的 content属性的值
[/b]
相关文章推荐
- Spring入门学习——配置文件<beans>属性配置记录
- (4) Spring中定时任务Quartz集群配置学习
- Spring中定时任务Quartz集群配置学习
- Spring中定时任务Quartz集群配置学习
- Spring中定时任务Quartz集群配置学习
- Spring中定时任务Quartz集群配置学习
- spring2 以后的配置文件解析 【待学习】
- spring + Quartz定时任务配置
- python 学习记录(11)-文件处理/读取文件/文件写入内容/文件删除/文件复制/文件重命名/后缀名/内容查找与替换/文件比较/ 配置文件访问/目录创建与删除/遍历目录/定向输出
- Quartz.Net 学习随手记之03 配置文件
- MyEclipse中XML的智能提示和关于Spring 配置文件头的一些记录和解释
- spring的配置文件记录
- Struts2学习记录(Struts2各项配置文件解析)
- Spring视频学习(十七)Spring配置文件总结
- Quartz.NET 2.0 学习笔记(3) :通过配置文件实现任务调度
- spring学习4-bean配置文件
- Quartz 框架快速入门(四)--配置文件通过Spring托管
- Quartz.NET 2.0 学习笔记(3) :通过配置文件实现任务调度
- spring 学习--beans.xml配置文件的讲解
- spring-security学习笔记--配置文件