Announcement Announcement Module
No announcement yet.
Populate cache on startup Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Populate cache on startup

    I am trying to populate some values from the database into the cache on Application startup.The cache has to be populated first thing for it to be available for other beans.

    What is the best way to do this?
    1. Should I use ContextLoaderListener and write my cache population logic in contextInitialized?
    2. Should I use bean init-method?


  • #2
    okay I created a quick implementation using ContextLoaderListener. But I have a problem. Here is my code and config.

    ContextLoaderListener :
    public class MyContextListener extends ContextLoaderListener {
    public void contextInitialized(ServletContextEvent event) {
    ServletContext ctx = event.getServletContext();
    WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContex t(ctx);

    PropManager manager = (PropManager) context.getBean("propManager");
    public void contextDestroyed(ServletContextEvent arg0) {}
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "">



    <!-- Http Flex Session attribute and binding listener support -->

    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>


    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>

    <!-- Map all *.service requests to the DispatcherServlet for handling -->

    I am having a problem. I am using Spring-BlazeDS integration, I get an exception
    as the MessageBrokerServlet is being loaded twice.

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '_messageBrokerDefaultHandlerMapping': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '_messageBroker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanInitializati onException: MessageBroker initialization failed; nested exception is java.lang.RuntimeException: MessageBroker already defined from MessageBrokerServlet with init parameter messageBrokerId = '_messageBroker'
    at AutowireCapableBeanFactory.doCreateBean(AbstractAu
    at AutowireCapableBeanFactory.createBean(AbstractAuto
    So what should I do?