@Autowired注释不适用于Project启动

时间:2014-09-12 16:38:35

标签: java spring spring-mvc autowired spring-portlet-mvc

我需要从数据库中获取一些值并在容器加载之前将其放入缓存中。我有一个实现ServletContextListener的Initializer类。这有contextInitialized()方法,它在服务器启动时被调用。我从这个Service方法调用一个类,然后调用我自动连接的DAO接口。我得到了Autowird异常,因为它没有采用@Autowired注释。我想使用Autowired anotation。有人请帮帮我。

我的Intilizer课程:

public class Initializer implements ServletContextListener{

    @Override
    public void contextInitialized(ServletContextEvent arg0) {

        StaticVariables.logger = Utility.getLogger();       
        IMasterServiceImpl iMasterServiceImpl = new IMasterServiceImpl();
        iMasterServiceImpl.setFunctionsConfigDataInCache();
    }
}

我的服务类:

@Autowired IMasterDAO iMasterDAO;
public void setFunctionsConfigDataInCache(){
        StaticVariables.logger.info("Entering in setFunctionsConfigDataInCache() method of IMasterServiceImpl.java");

        List<Function> functionsList=iMasterDAO.getFunctionConfigData(); //Getting Exception at this line//
        Map<String, Map<String,String>> functionsConfigMap = createFunctionConfigMap(functionsList);
        CacheManager cacheManager = new CacheManager();
        cacheManager.setObjectToCache("functionsConfigMap", functionsConfigMap);
        StaticVariables.logger.info("Exiting from setFunctionsConfigDataInCache() method of IMasterServiceImpl.java");
    }

例外:

[9/12/14 10:07:35:169 PDT] 00000025 webapp        E com.ibm.ws.webcontainer.webapp.WebApp notifyServletContextCreated SRVE0283E: Exception caught while initializing context: {0}
                                 java.lang.NullPointerException
    at com.zain.www.service.IMasterServiceImpl.setFunctionsConfigDataInCache(IMasterServiceImpl.java:55)

0 个答案:

没有答案