我是春天的新手,所以经过一整天的失败尝试后,我需要问一下;)
是否可以将Spring Boot和Spring shell结合在一起?
我的用例是构建一个包含 webapp 的 jar(Spring-boot 默认嵌入 jetty 或 tomcat),同时能够从 shell 执行一些项目命令。夸脱不是一种选择。如果这些命令和 webapp 共享相同的应用程序上下文,那就太好了。
我的 src/main/java 中有两个类(加上其他目录中的一些命令和控制器)
应用程序.java
package dk.mrok.carmonitor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Bootstrap webapp
*/
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
cli.java
package dk.mrok.carmonitor;
import java.io.IOException;
import org.springframework.shell.Bootstrap;
public class Cli {
/**
* Main class that delegates to Spring Shell's Bootstrap class in order to simplify debugging inside an IDE
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Bootstrap.main(args);
}
}
这是我的构建脚本:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'application'
apply plugin: 'idea'
jar {
baseName = 'carmonitor-backend'
version = '0.0.1'
}
repositories {
mavenCentral()
maven {url 'https://repo.spring.io/libs-snapshot'}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = "dk.mrok.carmonitor.Cli"
dependencies {
compile 'org.springframework.shell:spring-shell:1.2.0.BUILD-SNAPSHOT'
compile "org.springframework.boot:spring-boot-starter-web"
testCompile "junit:junit"
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
不幸的是,生成的 jar 是 spring-shell 项目,而不是 webapp。
执行 ./build/script/carmonitor (我期望这里的 shell 项目)输出
Error: Could not find or load main class dk.mrok.carmonitor.Cli
任何建议我做错了什么?