我有一个依赖于Spring 3的项目,我正在最新的spring boot项目中使用它
我遇到了自动布线的问题,我的Spring3项目有一个网关接口(IAccountGateway)
我正面临着这样的问题
Description:<br>
<br>Field iAccountGateway in
com.rvi.service.common.impl.RegistrationService required a bean of type
'com.rvi.jms.gateway.IAccountGateway' that could not be found. <br><br>Action:<br>
Consider defining a bean of type 'com.rvi.jms.gateway.IAccountGateway'
in your configuration.当我把debug放到我的spring项目中时,我得到了类似下面的日志
Registered injected element on class <br><br>
[com.rvi.service.common.impl.RegistrationService]:
AutowiredFieldElement for private com.rvi.jms.gateway.IAccountGateway
com.rvi.service.common.impl.RegistrationService.iAccountGateway发布于 2018-07-13 21:49:53
好吧,如果IAccountGateway是一个接口,那么您需要实现它并使用@Component注释将其定义为Spring Bean (还有一些other注释具有类似的效果)。
IAccountGateway.java
public interface IAccountGateway {
// ..
}AccountGatewayImpl.java ( IAccountGateway实现)
import org.springframework.stereotype.Component;
@Component
public class AccountGatewayImpl implements IAccountGateway {
// ..
}自动生成字段的:
import org.springframework.beans.factory.annotation.Autowired;
public class Clazz {
@Autowired
IAccountGateway iAccountGateway;
// ..
}请参阅Spring Boot Reference on Spring Beans and Dependency Injection
https://stackoverflow.com/questions/51318114
复制相似问题