3 回答
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
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>
大摇大摆的配置!!!
@Configuration
@EnableSwagger2WebMvc
@Import(SpringDataRestConfiguration.class)
public class SwaggerConfig {
添加回答
举报