我的测试类:@Autowired注解不能在JUnit类注入豆
public class myTest extends TestCase{
@Autowired
BeanClass beanObject
public void beanTest()
{
Classdata data = beanObject.getMethod();
}
}
我得到一个空指针异常在行:
Classdata data = beanObject.getMethod();
的beanObject.getMethod();
恰恰给了空指针异常
我应该如何使字段beanObject在我的Junit类中自动装配,以便我可以使用“BeanClass”类中的方法?
从评论复制:
纯术语.. beanClass是 接口,其具有某些方法.. 我已标记的是与beanClass
@Service("beanObject")
annotation..that banClass是 由beanClassImpl类 实施,其中有方法实现.. 我需要使用那些实现 我的testClass获取数据为 比较..因为我在做@Autowired
beanClass beanObject在 我testClass ..我要去可怕 错误的地方?
Spring应该从哪里得到`beanObject`?你有没有宣布它? – skaffman 2011-01-20 10:48:30
beanObject已经是一个beanClass对象,我已经将beanClass声明为@Service(“beanObject”)注释。 – alpesh003 2011-01-20 11:00:46