在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.spring work.boot</groupId>                      <artifactId>spring-boot-starter-web</artifactId>                  </exclusion>              </exclusions>          </dependency>       (3)、在项目打包的时候,也要exculde掉web相关依赖。          <build>              <plugins>                  <plugin>                      <groupId>org.spring work.boot</groupId>                      <artifactId>spring-boot-maven-plugin</artifactId>                      <configuration>                          <excludeArtifactIds>tomcat*</excludeArtifactIds>                          <excludeArtifactIds>spring-web</excludeArtifactIds>                          <excludeGroupIds>io.springfox</excludeGroupIds>                          <excludes>                              <exclude>                                  <groupId>org.spring work.boot</groupId>                                  <artifactId>spring-boot-starter-web</artifactId>                              </exclude>                              <exclude>                                  <groupId>org.spring work.boot</groupId>                                  <artifactId>spring-boot-starter-tomcat</artifactId>                              </exclude>                          </excludes>                      </configuration>                  </plugin>              </plugins>          </build>        然后将主入口文件写成:            import org.spring work.boot.CommandLineRunner;    import org.spring work.boot.SpringApplication;    import org.spring work.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!!!!!");        }    }     就成了一个单独的命令行程序。                                     
收藏 打印