[英]Injecting spring data repository into spring cloud function
我想在spring cloud功能中使用spring數據存儲庫功能。
我已經使用azure提供程序克隆了spring cloud功能: https : //github.com/spring-cloud/spring-cloud-function/tree/2.2.x/spring-cloud-function-samples/function-sample-azure
我有它在本地以及天藍色運行。
我要執行以下操作:
public class FooHandler extends AzureSpringBootRequestHandler<Foo, Bar> {
@Autowired
private FooRepository fooRepository;
@FunctionName("uppercase")
public Bar execute(
@HttpTrigger(name = "req", methods = { HttpMethod.POST}, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<Optional<Foo>> foo,
ExecutionContext context) {
fooRepository.insert(foo.getBody().get());
return handleRequest(foo.getBody().get(), context);
}
}
mongo回購示例:
import org.springframework.data.mongodb.repository.MongoRepository;
public interface FooRepository extends MongoRepository<Foo, String> {
}
結果是NullPointerException。 知道彈簧雲功能是否可行?
您將其注入錯誤的位置。 FooHandler只是調用uppercase
函數的委托。 因此,將其注入函數本身。
@Bean
public Function<Foo, Bar> uppercase(FooRepository fooRepository) {
return foo -> {
// do whatever you need with fooRepository
return new Bar(foo.getValue().toUpperCase());
};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.