为了账号安全,请及时绑定邮箱和手机立即绑定

找不到类型的属性

找不到类型的属性

子衿沉夜 2022-06-15 10:57:16
当运行我的代码从 Solr 获取数据时,它无法编译并出现异常:Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findSubscriptions found for type Subscriptions!我没有看到命名不一致或缺少方法。代码用于从 Solr 获取数据。我已经创建了一个文档,并且 Solr 已启动并在“ http://localhost:8983/solr/ ”上运行1)      @RestController      public class SubscriptionsController {      @Autowired      SolrSubscriptionsRepository solrSubscriptionsRepository;       @GetMapping("/subscriptions/{subscriptionId}")      public Subscriptions getSubscriptions(@PathVariable Long subscriptionId) {        solrSubscriptionsRepository.findSubscriptions(subscriptionId);        return solrSubscriptionsRepository.findSubscriptions(subscriptionId);      }2)     @SolrDocument(collection= "Subscriptions")     public class Subscriptions {     @Id     @Indexed(name="subscription_id", type="long")     private Long subscriptionId;     @Indexed(name="subscription_query", type="string")     private String subscriptionQuery;     @Indexed(name="subscription_type", type="string")     private String subscriptionType;     } 3)     public interface SolrSubscriptionsRepository extends      SolrCrudRepository<Subscriptions, Long>{     Subscriptions findSubscriptions(Long subscriptionId);     }4)      @Configuration      @EnableSolrRepositories(basePackages="com.test.repository")      @ComponentScan      public class SolrConfig {      @Value("spring.data.solr.host") String solrURL;      @Bean      public SolrClient solrClient() {        return new HttpSolrClient.Builder(solrURL).build();      }      @Bean      public SolrTemplate solrTemplate(SolrClient solrClient) throws Exception {        return new SolrTemplate(solrClient);        }      }5) application.propertiesspring.data.solr.host=http://localhost:8983/solr/
查看完整描述

1 回答

?
米脂

TA贡献1836条经验 获得超3个赞

解决方案1


@Autowired

  SolrSubscriptionsRepository solrSubscriptionsRepository; 


  @GetMapping("/subscriptions/{subscriptionId}")

  public Subscriptions getSubscriptions(@PathVariable Long subscriptionId) {


    solrSubscriptionsRepository.findSubscriptions(subscriptionId);

    return solrSubscriptionsRepository.findById(subscriptionId);

  }

解决方案2:


@Autowired

  SolrSubscriptionsRepository solrSubscriptionsRepository; 


  @GetMapping("/subscriptions/{subscriptionId}")

  public Subscriptions getSubscriptions(@PathVariable Long subscriptionId) {


    solrSubscriptionsRepository.findSubscriptions(subscriptionId);

    return solrSubscriptionsRepository.findBySubscriptionId(subscriptionId);

  }

public interface SolrSubscriptionsRepository extends SolrCrudRepository{

 Subscriptions findBySubscriptionId(Long subscriptionId);

 }


查看完整回答
反对 回复 2022-06-15
  • 1 回答
  • 0 关注
  • 81 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信