Allahbaksh Asadullah Allahbaksh Asadullah - 22 days ago 7
Java Question

Custom Implementation of Repositories Spring-Data-Cassandra

I am trying to use spring-data-cassandra custom repository implementation. I am using spring-data-cassandra 1.5.M1. The issue is the custom implementation method does not get executed.

Below is the code snippet.

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 {

}


The driver program of the same is below

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


Wether I am missing something?

Answer

rename JobRepositoryCustomImpl to JobRepositoryImpl:

Here is a example from my code:

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

}



interface ProductRepositoryCustom {
    public String anyFunction();
}

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