Announcement Announcement Module
Collapse
No announcement yet.
reading ClassPathRessource in application context config Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • reading ClassPathRessource in application context config

    Hi,

    i'm trying to attempt the following:

    In my application configuration i have the following:

    <beans>
    <bean id="MenuConfiguration"
    class="org.arachna.taglib.menu.MenuConfiguration"
    singleton="true">
    <constructor-arg>
    <ref bean="MenuConfigInputStreamFactory"/>
    </constructor-arg>
    </bean>

    <bean id="MenuConfigInputStreamFactory"
    factory-bean="MenuConfigurationResource"
    factory-method="getInputStream" />

    <bean id="MenuConfigurationResource"
    class="org.springframework.core.io.ClassPathResour ce">
    <constructor-arg>
    <value>classpath*:menu-config.xml</value>
    </constructor-arg>
    </bean>
    </beans>

    The last tow beans are solely for configuration of the first and to make it independent of Spring (really only needs it configuration as an InputStream).

    My problem is the definition of the last bean where i'd like to refer to a resource on the class path.

    On startup the application context attempts to initialize but fails to do so:

    ].[localhost].[/OrderIT] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListe ner
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'MenuConfiguration' defined in ServletContext resource [/WEB-INF/spring-beans.xml]: Can't resolve reference to bean 'MenuConfigInputStreamFactory' while
    setting property 'constructor argument'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'MenuConfigInputStreamFactory' defined in ServletContext resource [/WEB-INF/spring-beans.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.f
    actory.BeanDefinitionStoreException: Factory method [public java.io.InputStream org.springframework.core.io.ClassPathResource.getI nputStream() throws java.io.IOException] threw exception; nested exception is java.io.FileNotFoundException: class path resource [classpath*:menu-config.xml] cannot be opened because it does not exist

    The configuration file i attempt to read is in WEB-INF. What am i doing wron here?

    regards
    Dirk

  • #2
    The configuration file i attempt to read is in WEB-INF
    WEB-INF isn't on the classpath. Try moving it to WEB-INF/classes

    Comment


    • #3
      Thanks for your help. If all things were that simple...

      Comment


      • #4
        Weigo,

        You are trying to create a ClassPathResource pointing to multiple files, but one individual Resource can only point to _one_ actual resource (whether on the classpath or wherever). A Resource can in a way be thought of as an enhanced version of the standard java URL class.

        See here for more info:
        http://static.springframework.org/sp...resources.html

        The classpath*: prefix is a special prefix that is usable only in the constructor of application contexts. Internally it will resolve to multiple actual Resources.

        Comment


        • #5
          Thanks. I removed that already from my previous definition:

          <bean id="MenuConfigurationResource"
          class="org.springframework.core.io.ClassPathResour ce">
          <constructor-arg>
          <value>org/arachna/menu-config.xml</value>
          </constructor-arg>
          </bean>

          Works as advertised now

          Comment

          Working...
          X