Announcement Announcement Module
Collapse
No announcement yet.
How can I reference to an XML file which locates in dependency-jar? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I reference to an XML file which locates in dependency-jar?

    Hi all,

    In my program there is as usual the "spring-servlet.xml" which contains the injections of the classes. But some of the classes are referenced as ref="anotherRef". And the "anotherRef" is in the "applicationContext.xml" in a dependened jar.

    How can I reference to this "anotherRef"?

    Here is the sample codes.

    "spring-servlet.xml" in my program:
    Code:
    ...
    	<bean id="dslBean" parent="calculator" 
    		class="com.mycompany.DslBean">
    		<property name="productTemplateFile" value="/products/70010_PBLebenRisiko.xml"></property>
    	</bean>
    ...
    The parent="calculator" is defined in "applicationContext.xml" in other jar:
    Code:
    ...
    	<osgi:reference id="calculator"
    		interface="com.othercompany.Calculator" />
    ...

  • #2
    You can add the applicationContext.xml from your external jar in your web.xml like this:
    Code:
    	<servlet>
    		<servlet-name>Spring Servlet</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>classpath:applicationcontextinclasspath.xml applicationcontextinwebinf.xml</param-value>
    		</init-param>
    	</servlet>
    Spring can find resources in classpath, this is posible due to the prefix "classpath".

    Comment


    • #3
      My program is a Spring WS. My "web.xml" looks as follow:
      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
      	version="2.4">
      	<display-name>Archetype Created Web Application</display-name>
      
      	<!--  -->
      	<servlet>
      		<servlet-name>context</servlet-name>
      		<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
      		<load-on-startup>1</load-on-startup>
      	</servlet>
      	
      	<!--  -->
      	<servlet>
      		<servlet-name>spring-ws</servlet-name>
      		<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
      		<init-param>
      			<param-name>transformWsdlLocations</param-name>
      			<param-value>true</param-value>
      		</init-param>
      		<load-on-startup>1</load-on-startup>
      	</servlet>
      	<servlet-mapping>
      		<servlet-name>spring-ws</servlet-name>
      		<url-pattern>/*</url-pattern>
      	</servlet-mapping>
      </web-app>
      Here you can see I use the MessageDispatcherServlet and transformWsdlLocations. I am not sure if it will work using your method.

      Comment


      • #4
        It should work because
        Code:
        http://static.springframework.org/spring-ws/sites/1.5/apidocs/org/springframework/ws/transport/http/MessageDispatcherServlet.html
        extends
        Code:
        org.springframework.web.servlet.FrameworkServlet
        which handle config file location.

        Comment


        • #5
          I tried as follow:
          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
          	version="2.4">
          	<display-name>Archetype Created Web Application</display-name>
          
          	<!--  -->
          	<context-param>
          		<param-name>contextConfigLocation</param-name>
          		<param-value>/WEB-INF/applicationContext.xml</param-value>
          	</context-param>
          	
          	<!--  -->
          	<listener>
          		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          	</listener>
          
          	<!--  -->
          	<servlet>
          		<servlet-name>spring-ws</servlet-name>
          		<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
          		<init-param>
          			<param-name>transformWsdlLocations</param-name>
          			<param-value>true</param-value>
          		</init-param>
          		<load-on-startup>1</load-on-startup>
          	</servlet>
          	<servlet-mapping>
          		<servlet-name>spring-ws</servlet-name>
          		<url-pattern>/*</url-pattern>
          	</servlet-mapping>
          </web-app>
          Last edited by thomas2004; Sep 9th, 2008, 05:03 PM.

          Comment


          • #6
            I think my problem is not 100% solved.

            With my code I posted yesterday shown above. I can just access the *.xml file under src/main/webapp/WEB-INF. But as I want to access the *.xml file under scr/main/resources/META-INF, I get exception of FileNotFound. Here is my code:

            Code:
            <?xml version="1.0" encoding="UTF-8"?>
            <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
            	version="2.4">
            	<display-name>Archetype Created Web Application</display-name>
            
            	<!--  -->
            	<context-param>
            		<param-name>contextConfigLocation</param-name>
            		<param-value>classpath:../resources/META-INF/spring/applicationContext.xml</param-value>
            	</context-param>
            	
            	<!--  -->
            	<listener>
            		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
            	</listener>
            
            	<!--  -->
            	<servlet>
            		<servlet-name>spring-ws</servlet-name>
            		<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
            		<init-param>
            			<param-name>transformWsdlLocations</param-name>
            			<param-value>true</param-value>
            		</init-param>
            		<load-on-startup>1</load-on-startup>
            	</servlet>
            	<servlet-mapping>
            		<servlet-name>spring-ws</servlet-name>
            		<url-pattern>/*</url-pattern>
            	</servlet-mapping>
            </web-app>
            I try also:
            Code:
            ...
            	<context-param>
            		<param-name>contextConfigLocation</param-name>
            		<param-value>../resources/META-INF/spring/applicationContext.xml</param-value>
            	</context-param>
            I get the same exception.

            Someone has idea?

            Comment


            • #7
              Did you try this:

              Code:
              	
              <context-param>
              		<param-name>contextConfigLocation</param-name>
              		<param-value>classpath:/META-INF/spring/applicationContext.xml(2) /WEB-INF/applicationContext.xml (1)</param-value>
              	</context-param>
              The first (1) is the file in your project and the second(2) is the file in the classpath. I think you should not put "resources" in the path, because META-INF is in the root dir of the jar file.

              Comment


              • #8
                Thanks! I got it this time.

                Comment

                Working...
                X