2017-09-01 43 views
0

我想要一个工具,从负载方法连接起来,使可检索数据并把ehcache.The问题米朝里是@Autowiring没有内部MyBootstrapCacheLoaderFactory或任何其他类中工作(获得从加载方法调用)。我会很高兴,如果任何人都可以提供一些解决方案。创建每一个例子是不可能的,也没有它的帮助一些服务..提前感谢。ehcache的/ JVM启动

@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 
} 
+0

一个'@ Autowired'字段不能是'null'如果这将是应用程序将无法启动。您可能正在创建'TestingBootstrapCacheLoaderFactory'的新实例,而不是让Spring创建实例。 –

+0

嗨@ M.Deinum感谢reply.As你知道TestingBootstrapCacheLoaderFactory被称为在JVM startup.This的时间,我已经写了确切的代码,并抛出空指针,如果我试图抓住exception.I尝试使用自动装配,并与创建enviornment实例面对.environement.getproperty问题米抛出空pointer.Yaa想确认我的应用程序是starting.I试图从这个链接http://forums.terracotta.org/forums/posts/list/4335.page解决方案,但是,这是NT工作对于我 –

+0

如果我将尝试在此类中创建@Autowired Environment env,那么env将为空。 –

回答

0

给予@PostConstruct注释上面我的方法很适合我

+0

你能详细一点吗?这有什么帮助?你的PostConstruct方法是什么样的?你的createBootstrapCacheLoader()也会返回一个不同的类。你能详细谈谈这个班有什么。我也面临同样的问题,因为我试图从BootstrapLoader调用JPA接口方法。 – Manoj