亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我不能 @Autowired 一個 DatastoreRepository bean

我不能 @Autowired 一個 DatastoreRepository bean

慕萊塢森 2022-07-06 18:24:08
大多數 cygwin 程序不是二進制程序,而是腳本之一。該命令file可以為您提供文件類型的描述:$ file zcatzcat: POSIX shell script, ASCII text executable盡管$ file catcat: PE32+ executable (console) x86-64, for MS Windows讀取zcat的前5行$ head -n 5 zcat#!/bin/sh# Uncompress files to standard output.# Copyright (C) 2007, 2010-2016 Free Software Foundation, Inc.我們在第一行#!看到說這是一個由 /bin/sh解釋器執行的腳本。在其他情況下,我們可以有$ head -n5 2to3#!/usr/bin/python2.7.exeimport sysfrom lib2to3.main import mainsys.exit(main("lib2to3.fixes"))2to3python 2.7腳本也是如此
查看完整描述

3 回答

?
函數式編程

TA貢獻1807條經驗 獲得超9個贊

將此注釋 @EnableDatastoreRepositories 添加到您的 Application.java



查看完整回答
反對 回復 2022-07-06
?
慕田峪9158850

TA貢獻1794條經驗 獲得超7個贊

我認為問題在于您使用注釋的方式,嘗試將注入更改為構造函數,例如:


@RestController

public class AppUserController {



    private BookRepository bookRepository;


    @Autowired

    public AppUserController (

            BookRepository bookRepository){

        this.bookRepository= bookRepository;

    }



    @GetMapping("/booksave")

    public String helloworld() {

        bookRepository.save(new Book(3L, "author"));


        return "book saved";

    }


}

理解它的來源:Spring @Autowire on Properties vs Constructor


查看完整回答
反對 回復 2022-07-06
?
呼喚遠方

TA貢獻1856條經驗 獲得超11個贊

如何使用 Spring 數據休息:


    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-data-rest</artifactId>

    </dependency>

你不需要編寫控制器代碼


import org.springframework.cloud.gcp.data.datastore.repository.DatastoreRepository;

import org.springframework.data.rest.core.annotation.RepositoryRestResource;



@RepositoryRestResource(collectionResourceRel = "xxxxxs", path = "xxxx")

public interface XXXXXRepository extends DatastoreRepository<XXXXX, String> 

大搖大擺的配置?。。?/p>


@Configuration

@EnableSwagger2WebMvc

@Import(SpringDataRestConfiguration.class)

public class SwaggerConfig {


查看完整回答
反對 回復 2022-07-06
  • 3 回答
  • 0 關注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號