【问题标题】:NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.List<org.springframework.shell.ParameterResolver>'NoSuchBeanDefinitionException:没有“java.util.List<org.springframework.shell.ParameterResolver>”类型的限定bean
【发布时间】: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


    【解决方案1】:
    1. 如果您首先使用组件扫描,您将组件(Bean)放置在哪个路径并不重要,它会先在当前包中检查它,然后再检查它的子包。如果您的组件放置在不同的路径,则在 @ComponentScan("Path")

    2. 中包含该路径 1234563 /strong> 就在组件上方,因为 @SpringBootApplication 在启动时会扫描相同的组件。

    如果我回答错误,请告诉我您的回答并进一步详细说明。 快乐编码:)

    【讨论】:

    【解决方案2】:

    似乎无法解析您的 shell 命令参数。你可以试试这个:

    @ShellComponent class MyCommands {
      @ShellMethod("Add two integers together.") def add(
        @ShellOption(mandatory = true) a: Int, 
        @ShellOption(mandatory = true) b: Int): Int = a + b
    }
    

    【讨论】:

    • 根据docs.spring.io/spring-shell/docs/current/api/org/… 没有强制选项。我添加了 ShellOptions 没有任何成功。错误仍然存​​在。我已将最小示例上传到此处:github.com/Zethson/Scala-Spring-Shell-Example/tree/feature/… 如果您能看一下,将不胜感激。谢谢。
    • 我设法让它在 Java 中工作,仍在尝试在 Scala 中,但它并不简单
    • 你想出解决方案了吗?我还是迷路了。
    • 我无法让您的最小版本工作。我使这个 Scala 版本工作:@SpringBootApplication class DemoShellApplication object DemoApplication { def main(args: Array[String]) : Unit = SpringApplication.run(classOf[DemoShellApplication], args :_ *) } @ShellComponent class MyCommands { @ShellMethod("Add two integers together.") def add(a: Int, b: Int): Int = a + b } 使用 SBT 而不是 Maven。请注意,我使用了 Spring Boot 2.0 和 Spring Shell 2.0
    • 另外,如果您考虑从 Spring Shell 1.2 升级到 2.0,这可能会有所帮助 devops.datenkollektiv.de/…
    猜你喜欢
    • 2017-07-02
    • 2016-11-17
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 2017-04-05
    相关资源
    最近更新 更多