Results 1 to 8 of 8

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

  1. #1
    Join Date
    Jun 2007
    Posts
    159

    Default 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. #2
    Join Date
    Sep 2008
    Location
    Clermont-Ferrand
    Posts
    37

    Default

    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".
    :::::::::::::::::::::::::::::::::::::::::::::::
    Mickael Gervais
    Agaetis

    Site : www.agaetis.fr
    :::::::::::::::::::::::::::::::::::::::::::::::

  3. #3
    Join Date
    Jun 2007
    Posts
    159

    Default

    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.

  4. #4
    Join Date
    Sep 2008
    Location
    Clermont-Ferrand
    Posts
    37

    Default

    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.
    :::::::::::::::::::::::::::::::::::::::::::::::
    Mickael Gervais
    Agaetis

    Site : www.agaetis.fr
    :::::::::::::::::::::::::::::::::::::::::::::::

  5. #5
    Join Date
    Jun 2007
    Posts
    159

    Default

    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 at 04:03 PM.

  6. #6
    Join Date
    Jun 2007
    Posts
    159

    Default

    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?

  7. #7
    Join Date
    Sep 2008
    Location
    Clermont-Ferrand
    Posts
    37

    Default

    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.
    :::::::::::::::::::::::::::::::::::::::::::::::
    Mickael Gervais
    Agaetis

    Site : www.agaetis.fr
    :::::::::::::::::::::::::::::::::::::::::::::::

  8. #8
    Join Date
    Jun 2007
    Posts
    159

    Default

    Thanks! I got it this time.

Posting Permissions

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