2

I currently having an applicationContext.xml of an existing project. I created a new junit -Java project in which I kept the previous project as dependent project. I created an xml -ApplictionContextjunit.xml for the junit project.The question is- how I can reuse the existing applicationContext.xml in the new xml

This is my junit class entry-

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContextjunit.xml")
public class testJunit {

    private CustomerService cust;
}

This is my ApplictionContextjunit.xml--

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">



            <import resource="/spring-mvc/src/main/java/applicationContext.xml"/>
            <bean id="junit" class="com.junit.test.testJunit">
            <property name="cust" ref="cust"/>

            </bean>
            </beans>

This is my applicationContext.xml of the first project--

 <bean id="cust" class="com.krams.tutorial.dao.CustomerService">
        <property name="firstName" value="xxx"/>
        <property name="lastName" value="yyy"/></bean>

When running the testunit, its giving an exception--

    Offending resource: class path resource [applicationContextjunit.xml]; 
nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:/E:/eclipse-ws/junit-test/bin/spring-mvc/src/main/java/applicationContext.xml]; 
nested exception is java.io.FileNotFoundException: E:\eclipse-ws\junit-test\bin\spring-mvc\src\main\java\applicationContext.xml (The system cannot find the path specified)

this is my classpath entry--

 <classpathentry kind="src" path="src"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
        <classpathentry combineaccessrules="false" kind="src" path="/spring-mvc"/>
<classpathentry kind="output" path="bin"/>

spring-mvc is my first project. and this is the location of my applicationContext.xml spring-mvc\src\main\java\applicationContext.xml

But it is still searching for the applicationContext.xml in my jnuit project How to make my project identify the correct path of the applicationcontext.xml?? Thanks in advance

Dhara
  • 4,093
  • 2
  • 36
  • 69
Saurav
  • 111
  • 1
  • 4

0 Answers0