当运行我的代码从 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/
米脂
相关分类