您的位置:首页 > 编程语言 > Java开发

学习记录(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]

    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring quartz Jsoup