Announcement Announcement Module
Collapse
No announcement yet.
Load non-spring xml configuration file on startup Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Load non-spring xml configuration file on startup

    Hi!!

    I'm still a newbiw with Spring. Having said that, i'd like to do this:

    On application startup, i want to load an xml file located in the classpath, and process it so i build and object hierarchy with it, and have accessible for all the application.

    With struts, i did this:

    Code:
    public class MyActionServlet extends ActionServlet {
    
        public void init() throws ServletException {
    		super.init();
    		// Cargamos los ficheros de configuración y los valores necesarios
    		// en el contexto de la aplicacion
    		this.getServletContext().setAttribute(Constants.MAPA_ESTADOS,LeerConfiguracionEstados.ObtenerNavegacionEstados(this.getServletContext().getRealPath("/")+ File.separator + "WEB-INF" + File.separator + "classes" + File.separator + "tracking.xml"));
    		this.getServletContext().setAttribute(Constants.MAPA_TABLAS,LeerConfiguracionTablas.ObtenerDisposicionTablas(this.getServletContext().getRealPath("/")+ File.separator + "WEB-INF" + File.separator + "classes" + File.separator + "stateColumns.xml"));
            this.getServletContext().setAttribute("roles",LeerConfiguracionSeguridad.ObtenerInfoSeguridad(this.getServletContext().getRealPath("/")+ File.separator + "WEB-INF" + File.separator + "classes" + File.separator + "security.xml"));
    	}
    What's the spring-est way to replicate this behaviour?

    Thanks!!

  • #2
    You might want to have a look at Spring's Resource abstraction: http://static.springframework.org/sp...resources.html

    Comment


    • #3
      Spring's ContextLoaderListener should do what you want. It binds the ApplicationContext to the ServletContext. You can then get it with the WebApplicationContextUtils.getWebApplicationContex t() method.

      Comment


      • #4
        xstream!

        I would check out xstream, you can load an xml file and convert it to a object glyph in 5 lines of code. I like it a lot better than apache digester (but still the same idea)..


        http://xstream.codehaus.org/tutorial.html

        To reconstruct an object, purely from the XML:

        Person newJoe = (Person)xstream.fromXML(xml);

        Comment


        • #5
          I guess this all depends on what you are trying to do. If you could supply more details, I'm sure people can help.

          Comment

          Working...
          X