Caused by: java.io.FileNotFoundException: class path resource [../../resources/config/spring.xml] cannot be opened because it does not exist

Trying to use Spring's Test when it came to this error

Original code: 

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"../../../resources/config/spring.xml"})
public class TestFund {

    @Autowired
    private FundService fundService;

    @Test
    public void testFundSelectAll() {
        //System.out.println("所有基金: " + fundService.selectAll());
        System.out.println(fundService);
    }
}

 

Cause Analysis: 

  Modify the spring configuration file location spring.xml

Solution: 

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:config/spring.xml")
public class TestFund {

    @Autowired
    private FundService fundService;

    @Test
    public void testFundSelectAll() {
        //System.out.println("所有基金: " + fundService.selectAll());
        System.out.println(fundService);
    }
}

problem solved!

Guess you like

Origin www.cnblogs.com/zjulanjian/p/11088813.html