不能在没有@Inject构造函数的情况下提供,也不能从dagger中的@Providers注释方法提供



我在build.gradle.kts中添加了lombok依赖项作为

dependencies {
brazilGradle.run().forEach { runtimeOnly(it) }
brazilGradle.build().forEach { implementation(it) }
brazilGradle.testbuild().forEach { testImplementation(it) }
brazilGradle.tool("LambdaDaggerLauncher").forEach {
annotationProcessor(it)
compileOnly(it)
}
brazilGradle.tool("DaggerBuildTool").forEach {
annotationProcessor(it)
compileOnly(it)
}
// Gradle version of: <ht:import file="lombok/happier-trails.xml"/>
brazilGradle.tool("Lombok").forEach {
compileOnly(it)
annotationProcessor(it)
testCompileOnly(it)
testAnnotationProcessor(it)
}
}

已在配置文件中添加lombok依赖项

build-tools = {
1.0 = {

JDK11 = 1.0;
Lombok = 1.18.x;
LombokUtils = 1.1;
...
};
};

尝试添加LombokApi太

处理程序写为

@Slf4j
@AllArgsConstructor(onConstructor = @__({ @Inject}))
public class Handler implements RequestHandler<APIGatewayV2HTTPEvent, APIGatewayV2HTTPResponse> {
private final Service service;
@Override
public APIGatewayV2HTTPResponse handleRequest(final APIGatewayV2HTTPEvent apiGatewayV2HTTPEvent,
final Context context) {
log.info("Received input: {}", apiGatewayV2HTTPEvent);
return service.processRequest(apiGatewayV2HTTPEvent, context);
}
}

和dagger注射作为

@Singleton
@Component(modules = {AppModule.class})
public interface AppComponent {
@LambdaHandler(withAppConfig = true, appName = "Lambda")
Handler buildHandler();
}
@Module
public class AppModule {
@Provides
@Singleton
public Service getService(final ApiGatewayEventProcessor ApiGatewayEventProcessor) {
return new Service(ApiGatewayEventProcessor);
}
}

但我得到了这个错误:

error: com.amazon.lambda.Handler cannot be provided without an @Inject constructor or from an @Provides-annotated method. Handler buildHandler();

我错过了什么?我试着像一样直接使用@Inject

public class Handler implements RequestHandler<APIGatewayV2HTTPEvent, APIGatewayV2HTTPResponse> {
private final Service service;
@Inject
public Handler(final Service service) {
this.service = service;
}
@Override
public APIGatewayV2HTTPResponse handleRequest(final APIGatewayV2HTTPEvent apiGatewayV2HTTPEvent,
final Context context) {
log.info("Received input: {}", apiGatewayV2HTTPEvent);
return service.processRequest(apiGatewayV2HTTPEvent, context);
}

这是有效的。我对@AllArgsConstructor实现做错了什么

问题是巴西gradle依赖项的排序

将其更改为低于订单的

dependencies {
brazilGradle.run().forEach { runtimeOnly(it) }
brazilGradle.build().forEach { implementation(it) }
brazilGradle.testbuild().forEach { testImplementation(it) }
// Gradle version of: <ht:import file="lombok/happier-trails.xml"/>
brazilGradle.tool("Lombok").forEach {
compileOnly(it)
annotationProcessor(it)
testCompileOnly(it)
testAnnotationProcessor(it)
}
brazilGradle.tool("DaggerRuntime").forEach {
annotationProcessor(it)
compileOnly(it)
}
brazilGradle.tool("LambdaDaggerLauncher").forEach {
annotationProcessor(it)
compileOnly(it)
}
}

相关内容

最新更新