辉扬
2016-04-05 17:48
这是哪一个知识点,在哪个文件配置的文件参数呢?看到这里一脸懵逼~~~
我大概明白,我没有写那个UnitTestBase 类,也没有去继承它。。。
所以super父类的构造方法肯定会报错。。。晕菜,去看了下源码才察觉到那个类是自定 义的测试类。0 - 0
private ApplicationContext ctx;
@Before
public void init(){
ctx=new ClassPathXmlApplicationContext("spring-injection.xml");
}
@Test
public void testSetter(){
//ApplicationContext ctx=new ClassPathXmlApplicationContext("spring-injection.xml");
InjectionService service = (InjectionService) ctx.getBean("injectionService");
service.save("为什么会这样子呢?");
}这是我根据helloworld方法改的测试方法,也可以实现。
不过就是不懂 super("XML文件") 为什么行不通。。
package com.imooc.test.ioc.injection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import com.imooc.ioc.injection.service.InjectionService;
@RunWith(BlockJUnit4ClassRunner.class)
public class TestInjection {
public TestInjection(){
super("spring-injection.xml");
}
@Test
public void testSetter(){
//InjectionService service = super
}
}super那个出错了提示The constructor Object(String) is undefined
下面是我的项目结构,用的是myeclipse


没弄懂为什么super()出现什么问题,我上网去看一些helloworld可以用下面这方法读取解析xml文件。
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationcontext.xml");
HelloWorld helloworld=(HelloWorld)ctx.getBean("helloworld");
那个名字 叫
spring-injection.xml
其实这个就行web.xml一样的 懂没 只是名字变了而已
Spring入门篇
268798 学习 · 1026 问题
相似问题