如何解决如何将不为null的@RepositoryRestResource注入@RestController
在我的GCP端点项目中,@ RepositoryRestResource作为空注入到@RestController中。结果,我当然得到了一个NullPointer。如何将正确启动的存储库注入控制器?
遵循存储库类,控制器,应用程序和pom。
存储库:
A
控制器。
id cat flag value
0 1 A 1 V1
1 2 B 1 V2
2 3 A 1 V1
3 4 A 1 V3
4 5 B 1 V2
5 6 C 1 V4
6 7 A 1 V1
7 8 C 1 V4
8 9 D 0 NaN
9 10 E 0 NaN
10 11 D 0 NaN
还有pom.xml。
package com.katamlek.gcp_crystalloids;
@RepositoryRestResource
public interface PostRepository extends DatastoreRepository<Post,Long> {
}
应用程序:
package com.katamlek.gcp_crystalloids;
@Api
@RestController
public class PostController{
@Autowired
private PostRepository postRepository;
// dummy
@ApiMethod(path = "/hello",httpMethod = ApiMethod.HttpMethod.GET)
public DummyClass hello() {
return new DummyClass();
}
@ApiMethod(path = "/add",httpMethod = ApiMethod.HttpMethod.POST)
public Post post(@RequestBody Post post) {
return postRepository.save(post);
}
...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。