【发布时间】:2014-06-18 07:17:03
【问题描述】:
我有带有 spring-boot-starter-remote-shell 的 Spring Boot 应用程序。 当我放置这个 hello.groovy 脚本时,它会打印 'hello' ,这没关系。
package commands
import org.crsh.cli.Usage
import org.crsh.cli.Command
class hello {
@Usage("Say Hello")
@Command
def main(InvocationContext context) {
return "hello";
}
}
但是当我尝试注入一些 Spring bean 时,它总是为空。
package commands
import org.crsh.cli.Usage
import org.crsh.cli.Command
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import org.springframework.batch.core.launch.JobLauncher
@Component
class hello {
@Autowired
JobLauncher jobLauncher;
@Usage("Say Hello")
@Command
def main(InvocationContext context) {
if(jobLauncher != null){
return "OK";
}else{
return "NULL";
}
return "hello j";
}
}
我有@ComponentScan(basePackages={"com....", "commands"})
【问题讨论】:
-
例如,如果您在 GitHub 上提供一个最小的工作示例,将更容易找到答案。