SpringCloud----->在springboot项目中跑起来控制台项目

简介: 在springboot项目中跑起来控制台项目: springboot通常都是用来做restful api的web项目。 但是也有极少情况下,需要跑控制台项目,在去年的时候,我就遇到一个需求,需要把mysql数据库中的数据的增、删、改的数据准实时做数据清洗,也就是ETL工作,同步到公司的数据仓库greenplum中。
在springboot项目中跑起来控制台项目:
一个springboot的控制台项目:
    (1)、用spring-boot-starter替换掉spring-boot-starter-web,不然项目就会以web项目的方式启动.
    (2)、如果项目中有其他依赖了spring-boot-starter-web,必须exclude掉,例:
          <dependency>
              <groupId>com.xxxx.xxx</groupId>
              <artifactId>xxxx</artifactId>
              <exclusions>
                  <exclusion>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-starter-web</artifactId>
                  </exclusion>
              </exclusions>
          </dependency>   
    (3)、在项目打包的时候,也要exculde掉web相关依赖。
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-maven-plugin</artifactId>
                      <configuration>
                          <excludeArtifactIds>tomcat*</excludeArtifactIds>
                          <excludeArtifactIds>spring-web</excludeArtifactIds>
                          <excludeGroupIds>io.springfox</excludeGroupIds>
                          <excludes>
                              <exclude>
                                  <groupId>org.springframework.boot</groupId>
                                  <artifactId>spring-boot-starter-web</artifactId>
                              </exclude>
                              <exclude>
                                  <groupId>org.springframework.boot</groupId>
                                  <artifactId>spring-boot-starter-tomcat</artifactId>
                              </exclude>
                          </excludes>
                      </configuration>
                  </plugin>
              </plugins>
          </build>   
   
  然后将主入口文件写成:
        
    import org.springframework.boot.CommandLineRunner;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;

    @SpringBootApplication
    public class CanalclientApplication implements CommandLineRunner {

        public static void main(String[] args) {

            System.out.println("     Hello Springboot!!!!!");
            SpringApplication.run(CanalclientApplication.class, args);
        }

        @Override
        public void run(String... args) throws Exception {
            System.out.println("     This is console line!!!!!");
        }
    }
    
 就成了一个单独的命令行程序。
   
                          
        
相关文章
|
1月前
|
SpringCloudAlibaba Java 网络架构
【Springcloud Alibaba微服务分布式架构 | Spring Cloud】之学习笔记(二)Rest微服务工程搭建
【Springcloud Alibaba微服务分布式架构 | Spring Cloud】之学习笔记(二)Rest微服务工程搭建
46 0
|
30天前
|
负载均衡 Java API
Spring Cloud 面试题及答案整理,最新面试题
Spring Cloud 面试题及答案整理,最新面试题
132 1
|
30天前
|
Java Nacos Sentinel
Spring Cloud Alibaba 面试题及答案整理,最新面试题
Spring Cloud Alibaba 面试题及答案整理,最新面试题
139 0
|
1月前
|
SpringCloudAlibaba Java 持续交付
【构建一套Spring Cloud项目的大概步骤】&【Springcloud Alibaba微服务分布式架构学习资料】
【构建一套Spring Cloud项目的大概步骤】&【Springcloud Alibaba微服务分布式架构学习资料】
131 0
|
1月前
|
SpringCloudAlibaba Java 网络架构
【Springcloud Alibaba微服务分布式架构 | Spring Cloud】之学习笔记(七)Spring Cloud Gateway服务网关
【Springcloud Alibaba微服务分布式架构 | Spring Cloud】之学习笔记(七)Spring Cloud Gateway服务网关
81 0
|
3天前
|
负载均衡 Java 开发者
细解微服务架构实践:如何使用Spring Cloud进行Java微服务治理
【4月更文挑战第17天】Spring Cloud是Java微服务治理的首选框架,整合了Eureka(服务发现)、Ribbon(客户端负载均衡)、Hystrix(熔断器)、Zuul(API网关)和Config Server(配置中心)。通过Eureka实现服务注册与发现,Ribbon提供负载均衡,Hystrix实现熔断保护,Zuul作为API网关,Config Server集中管理配置。理解并运用Spring Cloud进行微服务治理是现代Java开发者的关键技能。
|
3天前
|
Java API 对象存储
对象存储OSS产品常见问题之使用Spring Cloud Alibaba情况下文档添加水印如何解决
对象存储OSS是基于互联网的数据存储服务模式,让用户可以安全、可靠地存储大量非结构化数据,如图片、音频、视频、文档等任意类型文件,并通过简单的基于HTTP/HTTPS协议的RESTful API接口进行访问和管理。本帖梳理了用户在实际使用中可能遇到的各种常见问题,涵盖了基础操作、性能优化、安全设置、费用管理、数据备份与恢复、跨区域同步、API接口调用等多个方面。
22 2
|
18天前
|
负载均衡 网络协议 Java
构建高效可扩展的微服务架构:利用Spring Cloud实现服务发现与负载均衡
本文将探讨如何利用Spring Cloud技术实现微服务架构中的服务发现与负载均衡,通过注册中心来管理服务的注册与发现,并通过负载均衡策略实现请求的分发,从而构建高效可扩展的微服务系统。
|
18天前
|
开发框架 负载均衡 Java
Spring boot与Spring cloud之间的关系
总之,Spring Boot和Spring Cloud之间的关系是一种构建和扩展的关系,Spring Boot提供了基础,而Spring Cloud在此基础上提供了分布式系统和微服务架构所需的扩展和工具。
16 4
Spring boot与Spring cloud之间的关系
|
1月前
|
SpringCloudAlibaba 负载均衡 Java
【Springcloud Alibaba微服务分布式架构 | Spring Cloud】之学习笔记(目录大纲)
【Springcloud Alibaba微服务分布式架构 | Spring Cloud】之学习笔记(目录大纲)
61 1