2014-12-04 62 views
1

我想了解spring data solr showcase项目。spring data solr showcase

https://github.com/christophstrobl/spring-data-solr-showcase

花费相当多的时间之后,我找不到productRepository如何实施https://github.com/christophstrobl/spring-data-solr-showcase/blob/master/src/main/java/org/springframework/data/solr/showcase/product/ProductServiceImpl.java

@Service class ProductServiceImpl implements ProductService { 
private static final Pattern IGNORED_CHARS_PATTERN = Pattern.compile("\\p{Punct}"); 
private ProductRepository productRepository; 


@Autowired 
public void setProductRepository(ProductRepository productRepository) { 
    this.productRepository = productRepository; 
} 

的ProductRepository注入被定义为接口(https://github.com/christophstrobl/spring-data-solr-showcase/blob/master/src/main/java/org/springframework/data/solr/showcase/product/ProductRepository.java)我没有发现任何代码实现这个接口

interface ProductRepository extends SolrCrudRepository<Product, String> { 

    @Highlight(prefix = "<b>", postfix = "</b>") 
    @Query(fields = { SearchableProductDefinition.ID_FIELD_NAME, 
         SearchableProductDefinition.NAME_FIELD_NAME, 
         SearchableProductDefinition.PRICE_FIELD_NAME, 
         SearchableProductDefinition.FEATURES_FIELD_NAME, 
         SearchableProductDefinition.AVAILABLE_FIELD_NAME }, 
      defaultOperator = Operator.AND) 
    HighlightPage<Product> findByNameIn(Collection<String> names, Pageable page); 

    @Facet(fields = { SearchableProductDefinition.NAME_FIELD_NAME }) 
    FacetPage<Product> findByNameStartsWith(Collection<String> nameFragments, Pageable pagebale); 
} 

下面是Spring上下文是如何配置: https://github.com/christophstrobl/spring-data-solr-showcase/blob/master/src/main/java/org/springframework/data/solr/showcase/Application.java

如果任何人都可以点我到这个接口被实现并注入的方向,那将是巨大的。

回答

2

展示使用Spring Data存储库抽象使用方法名称的查询派生。因此,Spring Data和Solr模块提供的基础架构负责为您创建所需的实施。请参阅Reference Documentation以获取更详细的解释。

展示柜本身的构建方式允许您通过查看从一个步骤到另一个步骤的差异的差异来查看step through several stages of development。因此,查看Step 2显示如何使用Custom Repository Implementation,而Step 4说明如何使用@Highlight启用突出显示。

+0

从马的嘴......感谢您的回应。 – Srik 2014-12-05 16:19:09

0

Spring Data的目标是减少样板编码的数量(意味着减少重复的代码)。
对于像save这样的基本方法,找到实现将会提供的spring和spring会为这些接口创建beans(Objetcs)。
告诉Spring,这些都是这个包在我的仓库,我们正在编写@EnableJpaRepositories(basePackeges="com.spring.repositories")<jpa:repositories base-package="com.acme.repositories"/>的JPA库
Foring Solr的repositores我们不得不写@EnableSolrRepositories(basePackages="com.spring.repositories"<solr:repositories base-package="com.acme.repositories" /> Spring将这些接口创建objetcs,我们可以通过注入这些接口objetcs @Autowire注释。

Example: 
@Service 
Pulic class SomeService{ 
    @Autowire 
    private SampleRepository; 

    /* @postConstruct annotation is used to execute method just after creating bean 
      and injecting all dependencies by spring*/ 
    @PostConstruct 
    public void postConstruct(){ 
      System.out.println("SampleRepository implementation class name"+ SampleRepository.getClass()); 
    } 
} 

上面的例子是看实现类SampleRepository接口(该类不是用户定义的,它是由弹簧给定类)。
仅供参考文件链接http://docs.spring.io/spring-data/solr/docs/2.0.2.RELEASE/reference/html/
尝试阅读这个简单的文档,你可以获得更多关于spring-data的知识。