jab*_*ena 2 executable-jar console-application spring-boot
我正在为非Web应用程序创建一个Spring-Boot应用程序,我想知道我必须使用什么插件或程序.
对于Micro服务开发,要添加的插件build.gradle是:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.6.RELEASE")
}
}
apply plugin: 'org.springframework.boot'
Run Code Online (Sandbox Code Playgroud)
但是,当你执行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
Run Code Online (Sandbox Code Playgroud)
还有其他选择
提前谢谢了.
Juan Antonio
你拥有的是一个良好的开端.
现在添加以下依赖项以获取所有Spring基础知识.
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile 'org.springframework.boot:spring-boot-starter-test'
}
Run Code Online (Sandbox Code Playgroud)
然后您的主类可以实现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);
}
}
Run Code Online (Sandbox Code Playgroud)
PS.如果你有Tomcat的启动首先要确保您的dependecy列表确实不包含spring-boot-starter-web.
| 归档时间: |
|
| 查看次数: |
961 次 |
| 最近记录: |