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

我是否错过了什么?

rename JobRepositoryCustomImpl to 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";
    }
}

相关内容

  • 没有找到相关文章

最新更新