кеширование с apache воспламеняется при загрузке пружины с использованием данных пружины - PullRequest
0 голосов
/ 24 апреля 2020
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)

hgjjhjhhhjhjhjjjhjhjjj ******************************** ************************************************** ************************************************** *******************************
Вы можете видеть, что часть кэширования не работала. Как я новичок в этом Технология, которую я не могу понять, что здесь не так. Может ли кто-нибудь помочь, пожалуйста?

1 Ответ

1 голос
/ 24 апреля 2020

Вам необходимо использовать @EnableIgniteRepositories. Для включения Apache Ignite резервных копий в данных Spring.

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

Взгляните на: https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/springdata/SpringDataExample.java

...