2017-08-30 79 views
2

我正在为非Web应用程序创建Spring-Boot应用程序,我想知道我必须使用的插件或过程。如何使用Spring Boot为非Web应用程序创建可执行Jar

中的微业务的发展,该插件在build.gradle补充说明的是:

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.6.RELEASE") 
    } 
} 

apply plugin: 'org.springframework.boot' 

但是,当你执行JAR产生,罐子启动一个Tomcat,并且不需要这样的软件:

`Java的罐子consoleApp-0.7.0-SNAPSHOT.jar演示= demo``

2017-08-30 14:48:13.505 INFO 82718 --- [   main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 
2017-08-30 14:48:13.510 INFO 82718 --- [   main] spring.ParamLoader      : Loading data... 
2017-08-30 14:48:13.510 INFO 82718 --- [   main] spring.ParamLoader      : item: 
2017-08-30 14:48:13.523 INFO 82718 --- [   main] spring.ConsoleApp      : Started ConsoleApp in 4.648 seconds (JVM running for 5.257) 
^C2017-08-30 14:48:18.502 INFO 82718 --- [  Thread-3] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot[email protected]6477463f: startup date [Wed Aug 30 14:48:09 CEST 2017]; root of context hierarchy 

任何替代?

非常感谢提前。

胡安·安东尼奥

+0

你不需要别的东西。什么是启动取决于依赖关系。如果您不包含tomcat(或其他支持的servlet容器),它将作为非web应用程序启动。 –

回答

5

你有什么是一个好的开始。

现在添加以下依赖项以获取所有Spring基础知识。

dependencies { 
    compile('org.springframework.boot:spring-boot-starter') 
    testCompile 'org.springframework.boot:spring-boot-starter-test' 
} 

然后你的主类可以实现org.springframework.boot.CommandLineRunner和您的应用程序可以在run方法开始工作。

@SpringBootApplication 
public class MyApplication implements CommandLineRunner { 
    @Override 
    public void run(String[] args) { 
    // do your work here 
    } 

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

PS。如果你有Tomcat首先开始确定你的依赖列表确实不是包含spring-boot-starter-web

+1

嗨@Strelok,问题在于你说的依赖。编译(“org.springframework.boot:spring-boot-starter:1.5.6.RELEASE”)以前:compile(“org.springframework.boot:spring-boot-starter-web:1.5.6.RELEASE”)当我删除后缀:网络,该应用程序有一个预期的行为。非常感谢。 – jabrena

相关问题