运行我的代码从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/
答案 0 :(得分:0)
解决方案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);
}