成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

spring cloud task Demo搭建

wanghui / 3364人閱讀

摘要:在中也可以看到執(zhí)行記錄,包括錯(cuò)誤信息解讀生命周期在任務(wù)開始之前即在初始化之后執(zhí)行任何或?qū)崿F(xiàn)之前創(chuàng)建一個(gè)記錄記錄開始事件的條目,此事件由觸發(fā),來向系統(tǒng)指出所有都可以使用。在加載完成所有的之后,任務(wù)執(zhí)行并更新數(shù)據(jù)庫中的執(zhí)行結(jié)果和狀態(tài),最后退出。

起步:什么是 spring cloud task

Spring Cloud Task makes it easy to create short lived microservices. We provide capabilities that allow short lived JVM processes to be executed on demand in a production environment.

Spring Cloud Task 是為了實(shí)現(xiàn)短生命周期的、定時(shí)執(zhí)行的、不需要被重新啟動(dòng)的輕量級(jí)應(yīng)用架構(gòu)。

創(chuàng)建 Demo

demo 已發(fā)布 https://github.com/Theembers/... 可以下載參考
1.首先需要?jiǎng)?chuàng)建一個(gè) springBoot 項(xiàng)目

2.除此以外需要加入數(shù)據(jù)庫依賴,Spring Cloud Task 支持主流數(shù)據(jù)庫(H2、HSQLDB、MySql、Oracle、Postgres)我們以mysql為例



    org.springframework.boot
    spring-boot-starter-data-jpa
    1.5.7.RELEASE


    mysql
    mysql-connector-java

3.引入task依賴

 

    org.springframework.cloud
    spring-cloud-task-core
    1.0.0.BUILD-SNAPSHOT

4.在application.properties中配置數(shù)據(jù)庫信息

#DB Configuration:
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/testdb
spring.datasource.username = root
spring.datasource.password = root

#JPA Configuration:
spring.jpa.database=MySQL
spring.jpa.show-sql=true  
spring.jpa.generate-ddl=true  
spring.jpa.hibernate.ddl-auto=update
#spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy  
#spring.jpa.database=org.hibernate.dialect.MySQL5InnoDBDialect
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MYSQL5Dialect

5.編寫你的Application

@SpringBootApplication
@EnableTask
public class SpringCloudTaskApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringCloudTaskApplication.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner() {
        return new TestCommandLineRunner();
    }

    public static class TestCommandLineRunner implements CommandLineRunner {
        @Override
        public void run(String... strings) throws Exception {
            System.out.println("this is a Test about spring cloud task.");
            try{
                List list = new ArrayList<>();
                list.get(1);
            }catch (Exception e){
                System.out.println("Error");
                throw e;
            }
        }
    }
}

注意: 以上代碼中通過異常的形式故意通過list.get(1)拋出,便于在數(shù)據(jù)庫中可以看到一些數(shù)據(jù)產(chǎn)生。

6.現(xiàn)在可以通過運(yùn)行main方法啟動(dòng)你的demo,以下是控制臺(tái)輸出:

  .   ____          _            __ _ _
 / / ___"_ __ _ _(_)_ __  __ _    
( ( )\___ | "_ | "_| | "_ / _` |    
 /  ___)| |_)| | | | | || (_| |  ) ) ) )
  "  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.7.RELEASE)

2017-09-25 17:02:43.349  INFO 11592 --- [           main] c.x.s.SpringCloudTaskApplication         : Starting SpringCloudTaskApplication on XinLing with PID 11592 (D:workspacesJavaspring-cloud-task	argetclasses started by theem in D:workspacesJavaspring-cloud-task)
2017-09-25 17:02:43.351  INFO 11592 --- [           main] c.x.s.SpringCloudTaskApplication         : No active profile set, falling back to default profiles: default
2017-09-25 17:02:43.383  INFO 11592 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@11c20519: startup date [Mon Sep 25 17:02:43 CST 2017]; root of context hierarchy
2017-09-25 17:02:43.938  INFO 11592 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit "default"
2017-09-25 17:02:43.947  INFO 11592 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2017-09-25 17:02:43.988  INFO 11592 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2017-09-25 17:02:43.989  INFO 11592 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-09-25 17:02:43.989  INFO 11592 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-09-25 17:02:44.016  INFO 11592 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Mon Sep 25 17:02:44 CST 2017 WARN: Establishing SSL connection without server"s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn"t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to "false". You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mon Sep 25 17:02:44 CST 2017 WARN: Establishing SSL connection without server"s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn"t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to "false". You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mon Sep 25 17:02:44 CST 2017 WARN: Establishing SSL connection without server"s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn"t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to "false". You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mon Sep 25 17:02:44 CST 2017 WARN: Establishing SSL connection without server"s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn"t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to "false". You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mon Sep 25 17:02:44 CST 2017 WARN: Establishing SSL connection without server"s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn"t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to "false". You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mon Sep 25 17:02:44 CST 2017 WARN: Establishing SSL connection without server"s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn"t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to "false". You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mon Sep 25 17:02:44 CST 2017 WARN: Establishing SSL connection without server"s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn"t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to "false". You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mon Sep 25 17:02:44 CST 2017 WARN: Establishing SSL connection without server"s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn"t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to "false". You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mon Sep 25 17:02:44 CST 2017 WARN: Establishing SSL connection without server"s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn"t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to "false". You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mon Sep 25 17:02:44 CST 2017 WARN: Establishing SSL connection without server"s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn"t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to "false". You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
2017-09-25 17:02:44.307  INFO 11592 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-09-25 17:02:44.406  INFO 11592 --- [           main] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2017-09-25 17:02:44.422  INFO 11592 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit "default"
2017-09-25 17:02:44.514  INFO 11592 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executing SQL script from class path resource [org/springframework/cloud/task/schema-mysql.sql]
2017-09-25 17:02:44.532  INFO 11592 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executed SQL script from class path resource [org/springframework/cloud/task/schema-mysql.sql] in 17 ms.
2017-09-25 17:02:44.636  INFO 11592 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-09-25 17:02:44.640  INFO 11592 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
this is a Test about spring cloud task.
Error
2017-09-25 17:02:44.675  INFO 11592 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with "debug" enabled.
2017-09-25 17:02:44.687  INFO 11592 --- [           main] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@11c20519: startup date [Mon Sep 25 17:02:43 CST 2017]; root of context hierarchy
2017-09-25 17:02:44.688  INFO 11592 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 0
2017-09-25 17:02:44.689  INFO 11592 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2017-09-25 17:02:44.689  INFO 11592 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit "default"
2017-09-25 17:02:44.698 ERROR 11592 --- [           main] o.s.boot.SpringApplication               : Application startup failed

java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:735) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:716) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:703) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:304) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at com.xz.springCoudTask.SpringCloudTaskApplication.main(SpringCloudTaskApplication.java:17) [classes/:na]
Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:653) ~[na:1.8.0_91]
    at java.util.ArrayList.get(ArrayList.java:429) ~[na:1.8.0_91]
    at com.xz.springCoudTask.SpringCloudTaskApplication$TestCommandLineRunner.run(SpringCloudTaskApplication.java:31) ~[classes/:na]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:732) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    ... 6 common frames omitted


Process finished with exit code 1

7.以下表會(huì)在第一次成功執(zhí)行后創(chuàng)建。

在task_execution中也可以看到執(zhí)行記錄,包括錯(cuò)誤信息

解讀 spring cloud task生命周期

1.在任務(wù)開始之前(即在spring初始化之后執(zhí)行任何CommandLineRunnerApplicationRunner實(shí)現(xiàn)之前)TaskRepository創(chuàng)建一個(gè)記錄記錄開始事件的條目,此事件SmartLifecycle#start由Spring Framework觸發(fā),來向系統(tǒng)指出所有bean都可以使用。

The recording of a task will only occur upon the successful bootstrapping of an ApplicationContext. If the context fails to bootstrap at all, the task’s execution will not be recorded.

任務(wù)的記錄只有當(dāng)bean可以成功加載時(shí)才會(huì)被記錄,如果失敗則不會(huì)被記錄。

2.在Spring Boot加載完成所有的bean之后,任務(wù)執(zhí)行并更新數(shù)據(jù)庫中的執(zhí)行結(jié)果和狀態(tài),最后退出。

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/70569.html

相關(guān)文章

  • 深入理解Spring Cloud與微服務(wù)構(gòu)建【二】 - 2.2 Spring Cloud

    摘要:負(fù)載均衡組件是一個(gè)負(fù)載均衡組件,它通常和配合使用。和配合,很容易做到負(fù)載均衡,將請(qǐng)求根據(jù)負(fù)載均衡策略分配到不同的服務(wù)實(shí)例中。和配合,在消費(fèi)服務(wù)時(shí)能夠做到負(fù)載均衡。在默認(rèn)的情況下,和相結(jié)合,能夠做到負(fù)載均衡智能路由。 2.2.1 簡(jiǎn)介 Spring Cloud 是基于 Spring Boot 的。 Spring Boot 是由 Pivotal 團(tuán)隊(duì)提供的全新 Web 框架, 它主要的特點(diǎn)...

    Rocko 評(píng)論0 收藏0
  • springcloud框架的簡(jiǎn)單搭建(服務(wù)注冊(cè)中心)

    摘要:必須要從零開始用搭建一下這個(gè)框架,本文是采用作為服務(wù)注冊(cè)與發(fā)現(xiàn)的組件。是一個(gè)默認(rèn)的注冊(cè)中心地址。配置該選項(xiàng)后,可以在服務(wù)中心進(jìn)行注冊(cè)。配置完成之后,啟動(dòng)項(xiàng)目,然后瀏覽器地址欄輸入然后出現(xiàn)以下頁面,表示注冊(cè)中心搭建完畢。 發(fā)現(xiàn)很多招聘都需要會(huì)springcloud,所以最近在學(xué)習(xí)springcloud。 必須要從零開始用IDEA搭建一下這個(gè)springcloud框架,本文是采用Eurek...

    蘇丹 評(píng)論0 收藏0
  • 墻裂推薦:搜云庫技術(shù)團(tuán)隊(duì),面試必備的技術(shù)干貨

    摘要:今天整理了一下近大半年以來的一些文章,和我的預(yù)期一樣,很多文章我都忘記自己曾經(jīng)寫過了,這個(gè)記錄的過程讓我也有了新的理解。希望大家,收藏,點(diǎn)贊,加轉(zhuǎn)發(fā)。 今天整理了一下近大半年以來的一些文章,和我的預(yù)期一樣,很多文章我都忘記自己曾經(jīng)寫過了,這個(gè)記錄的過程讓我也有了新的理解。希望大家,收藏,點(diǎn)贊,加轉(zhuǎn)發(fā)。 面試必備 面試必備:深入Spring MVC DispatchServlet 源碼...

    SegmentFault 評(píng)論0 收藏0
  • 墻裂推薦:搜云庫技術(shù)團(tuán)隊(duì),面試必備的技術(shù)干貨

    摘要:今天整理了一下近大半年以來的一些文章,和我的預(yù)期一樣,很多文章我都忘記自己曾經(jīng)寫過了,這個(gè)記錄的過程讓我也有了新的理解。希望大家,收藏,點(diǎn)贊,加轉(zhuǎn)發(fā)。 今天整理了一下近大半年以來的一些文章,和我的預(yù)期一樣,很多文章我都忘記自己曾經(jīng)寫過了,這個(gè)記錄的過程讓我也有了新的理解。希望大家,收藏,點(diǎn)贊,加轉(zhuǎn)發(fā)。 面試必備 面試必備:深入Spring MVC DispatchServlet 源碼...

    Neilyo 評(píng)論0 收藏0
  • springcloud框架的簡(jiǎn)單搭建(消費(fèi)服務(wù)基于feign)

    摘要:不過,我們搭建好框架就是為了消費(fèi)它使用它,那么這篇文章就來看看如何去消費(fèi)使用我們之前搭建起來的服務(wù)吧首先本文是基于上一篇文章進(jìn)行的。代碼如下啟動(dòng)程序,多次訪問,瀏覽器顯示內(nèi)容為至此我們這個(gè)服務(wù)消費(fèi)的框架就搭建完畢了。。。 上一篇文章主要介紹了如何搭建一個(gè)簡(jiǎn)單的springcloud框架。不過,我們搭建好框架就是為了消費(fèi)它使用它,那么這篇文章就來看看如何去消費(fèi)使用我們之前搭建起來的服務(wù)吧...

    xiguadada 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

wanghui

|高級(jí)講師

TA的文章

閱讀更多
最新活動(dòng)
閱讀需要支付1元查看
<