Results 1 to 3 of 3

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

  1. #1
    Join Date
    Sep 2008
    Posts
    8

    Default 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. #2
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    710

    Default

    Hi,

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

  3. #3
    Join Date
    Sep 2008
    Posts
    8

    Default

    I can try that. Thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •