使用Spring数据使用Spring Boot引导Apache点燃

问题描述 投票:0回答:1
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 ******************************************************* ****************************************************** ****************************************************** *********您会看到缓存部分无法正常工作。由于我是这项技术的新手,所以我无法弄清楚这里出现了问题。有人可以帮忙吗?

spring-boot caching spring-data ignite
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.