找不到类型的属性

当运行我的代码从 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.properties

spring.data.solr.host=http://localhost:8983/solr/


子衿沉夜
浏览 82回答 1
1回答

米脂

解决方案1@Autowired&nbsp; SolrSubscriptionsRepository solrSubscriptionsRepository;&nbsp;&nbsp; @GetMapping("/subscriptions/{subscriptionId}")&nbsp; public Subscriptions getSubscriptions(@PathVariable Long subscriptionId) {&nbsp; &nbsp; solrSubscriptionsRepository.findSubscriptions(subscriptionId);&nbsp; &nbsp; return solrSubscriptionsRepository.findById(subscriptionId);&nbsp; }解决方案2:@Autowired&nbsp; SolrSubscriptionsRepository solrSubscriptionsRepository;&nbsp;&nbsp; @GetMapping("/subscriptions/{subscriptionId}")&nbsp; public Subscriptions getSubscriptions(@PathVariable Long subscriptionId) {&nbsp; &nbsp; solrSubscriptionsRepository.findSubscriptions(subscriptionId);&nbsp; &nbsp; return solrSubscriptionsRepository.findBySubscriptionId(subscriptionId);&nbsp; }public interface SolrSubscriptionsRepository extends SolrCrudRepository{&nbsp;Subscriptions findBySubscriptionId(Long subscriptionId);&nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java