2013-02-28 102 views
0

我是新来的我和春天有我也有定义的bean称为自动装配豆

<bean id="offerpricedao" class="com.impl.OfferPriceDAOImpl" > 
    <constructor-arg index="0" ref="offerpriceclass"></constructor-arg> 
    <constructor-arg index="1" ref="myrole"></constructor-arg> 
    <constructor-arg index="2"><null/></constructor-arg> 
</bean> 

,我已经定义的每一个其他的bean在我的上下文文件

所以基本上自动装配bean的问题这里这是指.. 这个代码在src主要的Java .. 和SRC主要测试我有它加载该配置文件,在我的测试 我有这样

@ContextConfiguration(locations = { "classpath:Context.xml" }) 
public class SetOfferPricesTest extends AbstractTestNGSpringContextTests { 



    @Autowired 
     IOfferPriceDAO test; 
} 
有些事情TestNG的测试

和这种自动装配工作正常... 我认为我们应该在我的自动配线工作的配置文件中有这个.. 用这个如何我的自动装配工作..?

回答

0

你可能在上下文xml中有类似default-autowire="byName"的东西。当你添加@Autowired时,Spring发现该接口的实现并自动装载它。在你的情况下,实现为com.impl.OfferPriceDAOImpl

另外,@ContextConfiguration注释加载从classpath

0

上面的配置和代码上下文XML是不足以说明它是如何工作。

由于它的工作原理,所以bean是定义一些地方context.xml中或在context.xml中导入的XML文件。

dhanush说的也是如此。

相关问题