我正在为非 Web 应用程序创建一个 Spring-Boot 应用程序,我想知道我必须使用什么插件或程序。
对于微服务开发,在build.gradle
中添加的插件是:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.6.RELEASE")
}
}
apply plugin: 'org.springframework.boot'
但是,当你执行生成的Jar时,jar会启动一个Tomcat,不需要这种软件:
`java -jar consoleApp-0.7.0-SNAPSHOT.jar demo=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.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6477463f: startup date [Wed Aug 30 14:48:09 CEST 2017]; root of context hierarchy
还有其他选择吗?
非常感谢。
胡安安东尼奥
最佳答案
您拥有的是一个好的开始。
现在添加以下依赖项以获取所有 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);
}
}
附言。如果您首先启动了 Tomcat,请确保您的依赖项列表不包含spring-boot-starter-web
。
关于spring-boot - 如何使用 Spring Boot 为非 Web 应用程序创建可执行 Jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45960978/