Announcement Announcement Module
Collapse
No announcement yet.
Is there a way to run your own java program at Spring startup to perform diagnostics? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a way to run your own java program at Spring startup to perform diagnostics?

    I want to display all the mapped URLs for each controller, at Spring startup, when I run my application.
    This would be a program patterned off this code I found, below. I would want the program to run after
    the urls are mapped. This way, I could display exactly what is mapped and see if there are any mapping
    conflicts. Does anyone know what Spring class to extend to do this? Thanks for any advice on this.

    Code:
    Map<String, AbstractHandlerMethodMapping> map = WebApplicationContextUtils.getWebApplicationContext(servletContext).getBeansOfType(AbstractHandlerMethodMapping.class);
    Iterator<AbstractHandlerMethodMapping> iter = map.values().iterator();
    while (iter.hasNext()) {
        AbstractHandlerMethodMapping ahmb = iter.next();
        Iterator<Object> urls = ahmb.getHandlerMethods().keySet().iterator();
        while (urls.hasNext()) {
            Object url = urls.next();
            logger.error("URL mapped: " + url);
        }           
    }
    (See http://stackoverflow.com/questions/1...ven-url-spring)

  • #2
    Hi,

    can't you just write a listener that does the job? Just remember to declare it AFTER Spring's ApplicationContextListener in web xml!

    Comment


    • #3
      I can try that. Thanks.

      Comment

      Working...
      X