在现有的micronaut服务配置文件应用程序中,我添加了picocli依赖项,并创建了命令和命令测试规范。当我通过Intellij调试命令时,不会插入带注释的变量。特别是ingestClient为null。当我调试spock规范时,会发生注入。有什么我想念的吗?
这是命令:
package abbvie.esp.ingest.attache
import abbvie.esp.ingest.attache.model.LoadResult
import groovy.transform.CompileStatic
import io.micronaut.configuration.picocli.PicocliRunner
import io.reactivex.Flowable
import picocli.CommandLine.Command
import picocli.CommandLine.Option
import javax.inject.Inject
@CompileStatic
@Command(name = 'ingest', description = 'Command line tool to control ingestion of Attache Pro content into the search index.',
mixinStandardHelpOptions = true)
class IngestCommand implements Runnable {
@Inject
IngestClient ingestClient
@Option(names = ['-v', '--verbose'], description = '...')
boolean verbose
static void main(String[] args) throws Exception {
PicocliRunner.run(IngestCommand, args)
}
void run() {
Flowable<LoadResult> results = ingestClient.ingestCabinets()
for (LoadResult result : results.blockingIterable()) {
println result.id
}
}
}
这是规格:
package abbvie.esp.ingest.attache
import io.micronaut.configuration.picocli.PicocliRunner
import io.micronaut.context.ApplicationContext
import io.micronaut.context.env.Environment
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification
class IngestCommandSpec extends Specification {
@Shared
@AutoCleanup
ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST)
void "test with command line option"() {
given:
String[] args = ['-v'] as String[]
PicocliRunner.run(IngestCommand, ctx, args)
expect:
args.length > 0
}
}
答案 0 :(得分:2)
一个常见的问题是IntelliJ中尚未启用注释处理。
您可以通过选中“启用注释处理”复选框,在“构建,执行,部署>编译器>注释处理器”下启用注释处理。
另请参阅: https://docs.micronaut.io/latest/guide/index.html#ideSetup
PS。希望您喜欢picocli。享受吧!