0

I have some static block of content which need to load on startup of Spring MVC application.

static{
    // Added to use in the Log4J.xml file
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    System.setProperty("current.date", dateFormat.format(new Date()));
}

This 'current.date' property I am doing to use in the log4j.xml to set the current date. I don't know where to put this into Spring's context so that It can call every time when user runs the application.

Ashish Aggarwal
  • 3,018
  • 2
  • 23
  • 46
Subh
  • 414
  • 6
  • 14

2 Answers2

1

In the main bean, implement the InitializingBean interface. In this interface methods, put your above statements. They will run before initializing the bean.

user2550754
  • 884
  • 8
  • 15
  • http://www.codejava.net/coding/configure-log4j-for-creating-daily-rolling-log-files – Subh Aug 05 '13 at 20:24
0

I would suggest following:

  1. Put this code in the init() of a Servlet.
  2. Configure this servlet in web.xml.
  3. You can decide the order of loading (<load-on-startup/>) this servlet relative to other servlets.
  4. When the container loads, it initializes the servlet and calls its init() method executing the initialization code.
Santosh
  • 17,667
  • 4
  • 54
  • 79