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!!!!!");
        }
    }
    
 就成了一个单独的命令行程序。
   
                          
        
相关文章
|
2天前
|
前端开发 JavaScript Java
计算机Java项目|Springboot电影评论网站系统设计与实现
计算机Java项目|Springboot电影评论网站系统设计与实现
|
2天前
|
前端开发 JavaScript Java
计算机Java项目|基于Spring Boot的中小型医院网站的设计与实现
计算机Java项目|基于Spring Boot的中小型医院网站的设计与实现
|
2天前
|
JavaScript 前端开发 Java
计算机Java项目|基于SpringBoot+vue的人事系统
计算机Java项目|基于SpringBoot+vue的人事系统
|
2天前
|
前端开发 JavaScript Java
计算机Java项目|基于Spring Boot的宠物咖啡馆平台的设计与实现
计算机Java项目|基于Spring Boot的宠物咖啡馆平台的设计与实现
|
2天前
|
前端开发 JavaScript Java
计算机Java项目|基于SpringBoot的飘香水果购物网站
计算机Java项目|基于SpringBoot的飘香水果购物网站
|
2天前
|
前端开发 JavaScript Java
计算Java项目|基于SpringBoot的协力服装厂服装生产管理系统的设计与实现
计算Java项目|基于SpringBoot的协力服装厂服装生产管理系统的设计与实现
|
2天前
|
前端开发 JavaScript Java
计算机Java项目|Springboot社区医院信息平台
计算机Java项目|Springboot社区医院信息平台
|
2天前
|
数据采集 前端开发 JavaScript
计算机Java项目|Springboot师生健康信息管理系统
计算机Java项目|Springboot师生健康信息管理系统
|
2天前
|
前端开发 JavaScript Java
计算机Java项目|基于SpringBoot的IT技术交流和分享平台的设计与实现
计算机Java项目|基于SpringBoot的IT技术交流和分享平台的设计与实现
|
2天前
|
前端开发 JavaScript Java
计算机Java项目|基于Springboot的“衣依”服装销售平台的设计与实现
计算机Java项目|基于Springboot的“衣依”服装销售平台的设计与实现