简体   繁体   English

Spring Boot 不满足的依赖

[英]Spring Boot Unsatisfied dependency

I have the following code.我有以下代码。 I do believe that I create the beans properly but I keep getting this "Error creating bean with name...:Unsatisfied dependency expressed through field..."我确实相信我正确创建了 bean,但我不断收到此消息“使用名称创建 bean 时出错...:通过字段表达的不满意的依赖项...”

The code builds and runs well without the tests.代码在没有测试的情况下构建和运行良好。 But I need the tests...但我需要测试...

I've been searching high and low and no solution seems to work for me.我一直在寻找高低,似乎没有解决方案对我有用。 I've been dealing with this error for a while now, so any help would be great!我已经处理这个错误一段时间了,所以任何帮助都会很棒!

@Service(value = "serviceA")
public class ServiceA{

     @Autowired
     private ServiceB

     ...

}

@Service(value="serviceB")
public class ServiceB{
  
     ...

}

@SpringBootTest
@ContextConfiguration({"/app-name-mocks.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
public class TestingClass{
     
     @Autowired
     private ServiceA serviceA;

     @Autowired
     private ServiceB serviceB;

     ...
     
}

app-name-mocks.xml:

<bean id="serviceA" class="com.appname.service.ServiceA" />

<bean id="serviceB" class="org.easymock.EasyMock" 
      factory-method="createNiceMock">
      <constructor-arg name ="toMock"
          value="com.appName.service.ServiceB"/>
</beans>

It appears that Easymock isn't playing nice with Spring boot so I'll have to change stuff around and clean up the project a bit.看起来 Easymock 与 Spring Boot 的搭配不太好,所以我必须改变一些东西并稍微清理一下项目。 Thank you everyone!谢谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM