在项目启动期间加载ehcache / Jvm启动

时间:2017-09-01 13:03:35

标签: java spring spring-boot ehcache

我正在尝试从load方法连接一个工具,以便可以检索数据并放入ehcache。面临的问题是@AutowiringMyBootstrapCacheLoaderFactory内部或在任何其他类内部都没有工作(被调用从加载方法)。如果有人能提供一些解决方案,我将感到欣慰。创造每一个实例都是不可能的,也无法帮助提供某些服务。谢谢。事先谢谢。

@Component  
public class TestingBootstrapCacheLoaderFactory extends BootstrapCacheLoaderFactory implements BootstrapCacheLoader{

@Autowired
 Services service;

@Override
public BootstrapCacheLoader createBootstrapCacheLoader(Properties properties) {
    // TODO Auto-generated method stub
    return new MyBootstrapCacheLoaderFactory();
}

@Override
public Object clone() throws CloneNotSupportedException {
    // TODO Auto-generated method stub
    return super.clone();
}
public boolean isAsynchronous() {
    // TODO Auto-generated method stub
    return false;
}
public void load(Ehcache myCache) throws CacheException {
    // TODO Auto-generated method stub
    System.out.println("load your cache with whatever you want....");
    service.connect(); //null pointer as autowired doesnt work
    //nor it is working if i create a class object here and try to user 
    //other class for autowiring
}

1 个答案:

答案 0 :(得分:0)

在我的方法之上给出@Postconstruct注释为我工作