【发布时间】:2019-05-28 14:34:30
【问题描述】:
我目前正在尝试在 Scala 中创建一个 Spring Shell 应用程序。 它在 IntelliJ 中工作,但在创建 jar 时不起作用。
我有一个 Java 概念的工作证明,它也成功地创建了一个运行的 jar。
但是,我的 Scala 版本失败了几个:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'parameterValidationExceptionResultHandler': Unsatisfied dependency expressed through field 'parameterResolvers'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.List<org.springframework.shell.ParameterResolver>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
我尝试了几个最小的示例,移动类(相同的包)和不同的 Spring 注释(如两者的 @SpringBootApplication)。
Java 版本:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@ShellComponent
public class MyCommands {
@ShellMethod("Add two integers together.")
public int add(int a, int b) {
return a + b;
}
}
Scala 版本:
@EnableAutoConfiguration
@ComponentScan
class DemoApplication
object Scark extends App {
SpringApplication.run(classOf[DemoApplication], args:_*)
}
@ShellComponent class MyCommands {
@ShellMethod("Add two integers together.") def add(a: Int, b: Int): Int = a + b
}
我希望也能够从 Scala 版本成功构建一个 jar。
编辑:我上传了最小的例子: https://github.com/Zethson/Scala-Spring-Shell-Example/tree/feature/minimal_scala_issues_SO
【问题讨论】:
标签: java spring scala shell spring-boot