spring - 通过对象属性表达的不满足的依赖关系
当尝试使用 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>
我对 spring 不太熟悉,所以我不确定这里的问题是什么。有什么想法吗?
I am receiving the following error when attempting to inject my dao into a unit test class using spring.
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.
Here is the segment of my spring config file that is relevant:
<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>
I'm not very familiar with spring so I'm unsure of what the problem is here. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您的测试没有使用定义 FruitDao bean 的上下文,从而阻止了它的自动装配...检查 GetContext/ConfigLocations 方法以确保加载预期的 XML 文件。
It seems your test does not use the context where you defined your FruitDao bean, thus preventing its autowiring... Check the GetContext/ConfigLocations methods to be sure you load the expected XML files.