Spring data 将spring数据存储库注入spring云函数

Spring data 将spring数据存储库注入spring云函数,spring-data,spring-cloud-function,Spring Data,Spring Cloud Function,我想在SpringCloud函数中使用spring数据存储库功能 我已使用azure provider克隆了spring云功能: 我让它在本地和azure上运行 我想做以下工作: public class FooHandler extends AzureSpringBootRequestHandler<Foo, Bar> { @Autowired private FooRepository fooRepository; @FunctionName("upp

我想在SpringCloud函数中使用spring数据存储库功能

我已使用azure provider克隆了spring云功能:

我让它在本地和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);
    }

}
公共类FooHandler扩展AzureSpringBootRequestHandler{
@自动连线
私人食物储存库;
@FunctionName(“大写”)
公共酒吧执行(
@HttpTrigger(name=“req”,methods={HttpMethod.POST},authLevel=AuthorizationLevel.FUNCTION)HttpRequestMessage foo,
ExecutionContext(上下文){
insert(foo.getBody().get());
返回handleRequest(foo.getBody().get(),context);
}
}
mongo回购示例:

import org.springframework.data.mongodb.repository.MongoRepository;

public interface FooRepository extends MongoRepository<Foo, String> {
}

import org.springframework.data.mongodb.repository.MongoRepository;
公共接口FooRepository扩展了MongoRepository{
}

结果是NullPointerException。你知道spring云功能是否可行吗?

你在错误的地方注入了它。FooHandler只是一个调用
大写
函数的委托。因此,将其注入函数本身

@Bean
public Function<Foo, Bar> uppercase(FooRepository fooRepository) {
    return foo -> {
        // do whatever you need with fooRepository
        return new Bar(foo.getValue().toUpperCase());
    };
}
@Bean
公共函数大写(FooRepository FooRepository){
返回foo->{
//用fooRepository做任何你需要的事情
返回新条(foo.getValue().toUpperCase());
};
}