存储库Spring-Data-Cassandra的自定义实现

时间:2016-11-12 07:03:27

标签: java spring spring-data spring-data-cassandra

我正在尝试使用spring-data-cassandra自定义存储库实现。我使用的是spring-data-cassandra 1.5.M1。问题是自定义实现方法没有被执行。

以下是代码段。

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;
    }
}

我错过了什么?

1 个答案:

答案 0 :(得分: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";
    }
}