1
嗨,朋友我使用弹性搜索与春季启动项目和我的主要数据库是MySQL。我的项目使用默认配置运行良好。假设我的实体是CancelReason.java如何在使用elasticsearch的实体中重命名id字段?
@Entity
@Table(name = "cancel_reason")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "cancelreason")
public class CancelReason implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotNull
@Size(max = 10)
@Column(name = "reason_code", length = 10, nullable = false)
private String reasonCode;
.......
}
现在有了这个配置我的项目运行和弹性搜索工作正常,但我是需求量的使reasonCode
主键代替id
,所以我想删除
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
此代码。如我删除id字段,并reasonCode PrimaryKey的,当我跑我的项目它给我这个错误:
[WARN] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cancelReasonManager': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.megacabs.repository.search.CancelReasonSearchRepository in.megacabs.manager.CancelReasonManager.cancelReasonSearchRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cancelReasonSearchRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No id property found for class in.megacabs.domain.CancelReason!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
at in.megacabs.Application.main(Application.java:77) [classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.megacabs.repository.search.CancelReasonSearchRepository in.megacabs.manager.CancelReasonManager.cancelReasonSearchRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cancelReasonSearchRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No id property found for class in.megacabs.domain.CancelReason!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
虽然MySQL是做工精细实体在mysql数据库beign创建,但在elasticsearch。 请帮忙!
你能提供完整的堆栈跟踪吗? – talex
我已经编辑stacktrace和我使用jhipster来使这个项目 – Qasim
那么,Stacktrace说它不能创建cancelReasonSearchRepository。我不认为这是一个弹性搜索问题。更改了CancelReason类后,是否更改了存储库?也许发布存储库(没有方法)和新的CancelReason实现可以帮助我们发现问题。 – Slomo