spring - 通过对象属性表达的不满足的依赖关系

发布于 2024-11-11 17:59:38 字数 1204 浏览 3 评论 0原文

当尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

絕版丫頭 2024-11-18 17:59:38

看来您的测试没有使用定义 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文