2016-11-12 127 views
0

我正在嘗試使用spring-data-cassandra定製存儲庫實現。我正在使用spring-data-cassandra 1.5.M1。問題是自定義實現方法沒有得到執行。定製實現存儲庫Spring-Data-Cassandra

下面是代碼片段。

public interface JobRepositoryCustom{ 
    public Job getJobById(String id); 
} 

@Component 
public class JobRepositoryCustomImpl implements JobRepositoryCustom{ 
    @Autowired 
    CassandraOperations template; 

    public Job getJobById(String job) { 


     System.out.println("Some custom implementation"); 
     return job; 
    } 
} 

public interface JobRepository extends TypedIdCassandraRepository<Job,String>, JobRepositoryCustom { 

} 

相同的驅動程序是下面

@SpringBootApplication 
public class App { 
    public static void main(String[] args) { 
     SpringApplication.run(App.class); 
    } 
    @Bean 
    public CommandLineRunner demo(JobRepository repository) { 
     Job job = new Job(); 
     job.setId("1817086421"); 
     job.setDescription("My job2 description"); 
     job.setOneMoreField("Just a new field"); 
     job.setTitle("Technical Engineer job"); 
     repository.save(job); 
     //The getJobById is custom method declared in JobRepositoryCustom 
     repository.getJobById("My String"); 
     System.out.println("This after the job"); 
     System.out.println("repository = [" + repository+ "]"); 
     return null; 
    } 
} 

閹我失去了一些東西?

回答

2

命名JobRepositoryCustomImpl到JobRepositoryImpl:

這裏是我的代碼示例:

public interface ProductRepository extends JpaRepository<Product, Long>, ProductRepositoryCustom { 

} 



interface ProductRepositoryCustom { 
    public String anyFunction(); 
} 

@Repository 
class ProductRepositoryImpl implements ProductRepositoryCustom { 
    @Override 
    public String anyFunction(){ 
     return "Hello"; 
    } 
} 
+2

'@ Repository'上'不需要ProductRepositoryCustom'。除此之外,這是正確的答案。 – mp911de