0
I am trying to do caching with  apache ignite 2.7.5  in spring boot 2. Here application starts and ignite node is up but the caching is not working (i dont have any errors in console).

Here is my config file
@Bean
public Ignite igniteInstance() {

        IgniteConfiguration  cfg = new IgniteConfiguration();

        cfg.setIgniteInstanceName("springDataNode");
        cfg.setPeerClassLoadingEnabled(true);

        CacheConfiguration    studcfg = new CacheConfiguration("studentCache");
        CacheConfiguration    coursecfg = new CacheConfiguration("courseCache");

        studcfg.setIndexedTypes(Long.class,Student.class);
        coursecfg.setIndexedTypes(Long.class,Course.class);

        cfg.setCacheConfiguration(new CacheConfiguration[] {studcfg,coursecfg});
        return Ignition.start(cfg);     
    }
*************************************************************************
here is my repositories
@RepositoryConfig(cacheName = "studentCache")
public interface StudentRepository extends IgniteRepository<Student,Long> {

    List<Student> getStudentByName(String name);
    Student getStudentById (Long id);
}
@RepositoryConfig(cacheName = "courseCache")
public interface CourseRepository extends IgniteRepository<Course, Long> {


    List<Course> getAllCourseByName (String name);

    @Query("SELECT id FROM Breed WHERE id = ?")
    List<Long> getById (Long id, Pageable pageable);

}

here is the caching part
public class CacheApp {

    private static   AnnotationConfigApplicationContext ctx;

    @Autowired
    private static   StudentRepository studentRepository;

    @Autowired
    private static   CourseRepository courseRepository;


    public static void main(String[] args)
        {
            System.out.println( "Spring Data Example!" );
            ctx = new AnnotationConfigApplicationContext();
            ctx.register(SpringConfig.class);
            ctx.refresh();

            studentRepository= ctx.getBean(StudentRepository.class);
            courseRepository= ctx.getBean(CourseRepository.class);

            Student stud1= new Student();
            stud1.setId(111);
            stud1.setName("ram");
            studentRepository.save(stud1);

            List<Student> getAllBreeds = studentRepository.getStudentByName("ram");

            for(Student student : getAllBreeds){
                System.out.println("student:" + student);
            }

            Course course1= new Course();
            course1.setId(1);
            course1.setName("maths");
            courseRepository.save(course1);

            List<Course> courses = courseRepository.getAllCourseByName("maths");
            for(Course cor : courses){
                System.out.println("courses:"+ cor);
            }
      }
}

here is my console log
    01:32:56] Ignite node started OK (id=2eb50680, instance name=springDataNode)
    2020-04-25 01:32:56.427  INFO 5056 --- [           main] o.a.i.i.IgniteKernal%springDataNode      : Data Regions Configured:
    2020-04-25 01:32:56.427  INFO 5056 --- [           main] o.a.i.i.IgniteKernal%springDataNode      :   ^-- default [initSize=256.0 MiB, maxSize=799.3 MiB, persistence=false]
    2020-04-25 01:32:56.428  INFO 5056 --- [           main] o.a.i.i.IgniteKernal%springDataNode      : 

    >>> +----------------------------------------------------------------------+
    >>> Ignite ver. 2.7.5#20190603-sha1:be4f2a158bcf79a52ab4f372a6576f20c4f86954
    >>> +----------------------------------------------------------------------+
 ..........................................................
    [01:32:56] Topology snapshot [ver=1, locNode=2eb50680, servers=1, clients=0, state=ACTIVE, CPUs=4, offheap=0.78GB, heap=0.87GB]
    2020-04-25 01:32:56.431  INFO 5056 --- [           main] o.a.i.i.m.d.GridDiscoveryManager         : Topology snapshot [ver=1, locNode=2eb50680, servers=1, clients=0, state=ACTIVE, CPUs=4, offheap=0.78GB, heap=0.87GB]
    2020-04-25 01:32:56.547  INFO 5056 --- [           main] com.example.demo.IgniteTestApplication   : Started IgniteTestApplication in 4.761 seconds (JVM running for 5.566)

hgjjhjhhhjhjhjjjhjhjjh************************************************************************************************************************************************************
You can see that caching part was not working.As I am new to this technology I am unable to figure out want has went wrong here.Can anyone please help?

5
  • Why do you think it's not working? Don't see any errors here. Commented Apr 25, 2020 at 18:36
  • thats the problem almar cacheApp part is not working ,it is not showing any erros too. I am trying to do simple caching using ignite in boot Commented Apr 25, 2020 at 19:56
  • I don't even see your Spring Data Example! being logged. Are you sure that this main() runs at all? Commented Apr 27, 2020 at 11:54
  • it isnt... and i am unable to understand the reason Commented Apr 27, 2020 at 12:57
  • I think that Spring Boot does not run your CacheApp as main class, it has main class of its own. Commented Apr 27, 2020 at 13:11

1 Answer 1

1

You need to use @EnableIgniteRepositories To enable Apache Ignite backed repositories in Spring Data.

see: https://apacheignite-mix.readme.io/docs/spring-data#spring-data-and-apache-ignite-configuration

Take a look at: https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/springdata/SpringDataExample.java

Sign up to request clarification or add additional context in comments.

1 Comment

the problem here is the cacheApp part is somehow to working ,,,if check the logs you can see that it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.