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

时间:2021-02-05 23:10:30

I am trying to connect a tool from load method so that can retrieve data and put inside ehcache.The problem m facing is @Autowiring is not working inside MyBootstrapCacheLoaderFactory nor inside any other class(getting called from load method). I will be gratified if anyone can provide some solution.Creating Each and every instance is not possible nor its helping with some services..Thanks in advance.

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

@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 个解决方案

#1


0  

Giving @Postconstruct annotation above my method worked for me

在我的方法之上给@Postconstruct注释工作对我有用

#1


0  

Giving @Postconstruct annotation above my method worked for me

在我的方法之上给@Postconstruct注释工作对我有用