尝试使用spring将我的dao注入单元测试类时,我收到以下错误。
UnitTest.DataAccess.FruitDaoTest.GetAllVitaminC:
SetUp : Spring.Objects.Factory.UnsatisfiedDependencyException : Error creating object with name 'FruitDaoTest' : Unsatisfied dependency expressed through object property 'FruitDao': Set this property value or disable dependency checking for this object.
以下是我的spring配置文件的相关部分:
<db:provider
id="DbProvider"
provider="SqlServer-2.0"
connectionString="Data Source=stuff.group.stuff;Initial Catalog=zing;User ID=Marve; Password=stinky" />
<object id="transactionManager" type="Spring.Data.Core.AdoPlatformTransactionManager, Spring.Data">
<property name="DbProvider" ref="DbProvider" />
</object>
<object id="FruitDao" type="FruitBasket.DataAccess.FruitDao, FruitBasket">
<property name="DbProvider" ref="DbProvider"/>
<property name="user" value="apple" />
<property name="pass" value="orange" />
<property name="server" value="pear" />
</object>
我对弹簧不太熟悉所以我不确定这里的问题是什么。有什么想法吗?
答案 0 :(得分:2)
您的测试似乎没有使用您定义FruitDao bean的上下文,从而阻止其自动装配...检查GetContext / ConfigLocations方法以确保加载预期的XML文件。