问答详情
源自:2-2 Spring注入方式

spring-injection.xml放在哪里,UnitTestBase是如何找到它的?

报错: IOException parsing XML document from class path resource [spring-injection.xml]; nested exception is java.io.FileNotFoundException:

class path resource [spring-injection.xml] cannot be opened because it does not exist

应该怎样存放?

提问者:南柯三梦 2016-05-11 20:54

个回答

  • qq_裸奔的蜗牛_1
    2016-05-12 08:49:13
    已采纳

    一般放在与包同级目录下,在类里使用ClassPathXmlApplicationContext cpx=new ClassPathXmlApplicationContext("spring-injection.xml")找到;getBean("beanId")获取配置好的注入对象