如何解决如何在Elasticsearch中存储Hateoas结构
我有以下问题,我需要使用Springboot应用程序中的save方法在Elasticsearch中保存一个Hateos结构,但是我收到错误消息“ stackoverflowerror null”:请问有什么机构可以检查我的代码以查看我的位置犯错误 ?我花了很长时间来演示这个例子。
Config.java
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.example.demo.elsticsearch")
public class Config {
@Bean
public RestHighLevelClient client() {
ClientConfiguration clientConfiguration
= ClientConfiguration.builder()
.connectedTo("localhost:9200")
.build();
return RestClients.create(clientConfiguration).rest();
}
@Bean
public ElasticsearchOperations elasticsearchTemplate() {
return new ElasticsearchRestTemplate(client());
}
}
UserResourceAssembler.java
@Service
public class UserResourseAssembler extends RepresentationModelAssemblerSupport<User,UserResourse> {
public UserResourseAssembler() {
super(JsController.class,UserResourse.class);
}
@Override
public UserResourse toModel(User user) {
UserResourse resource = UserResourse.builder().email("jjj").firstName("hii").lastName("hoo").loginId("123").build();
resource.add(linkTo(methodon(JsController.class).getByLoginId(user.getLoginId())).withRel("self"));
return resource;
}
}
Repo.java
@Repository
public interface Repo extends ElasticsearchRepository<UserResourse,String> {
List<UserResourse> findByLoginId(String loginId);
}
User.java
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
private String loginId;
private String firstName;
private String lastName;
private String email;
}
UserResourse.java
@Mapping(mappingPath = "/files.json")
@Document(indexName = "files",type = "file")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UserResourse extends RepresentationModel<UserResourse> {
@Id
private String loginId;
private String firstName;
private String lastName;
private String email;
}
JsController.java
@RestController
@RequestMapping("/user")
@AllArgsConstructor
public class JsController {
private final Repo repository;
private final UserResourseAssembler userResourseAssembler;
@GetMapping("/check")
public ResponseEntity<UserResourse> uploadData() {
User user = new User(UUID.randomUUID().toString(),"hi","hello","jj");
UserResourse userResourse = userResourseAssembler.toModel(user);
repository.save(userResourse);
return new ResponseEntity<>(userResourse,HttpStatus.OK);
}
@GetMapping("/jobId")
public List<UserResourse> getByLoginId(@PathVariable String loginId) {
return repository.findByLoginId(loginId);
}
}
我遇到以下错误:
2020-09-18 10:02:35.939 ERROR 16184 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing Failed; nested exception is org.springframework.data.elasticsearch.ElasticsearchException: Cannot render document to JSON] with root cause
java.lang.StackOverflowError: null
at java.base/java.lang.classLoader.defineClass1(Native Method) ~[na:na]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。