我正在开发一个spring-ws网络服务,在该服务中调用银行网络服务。
这是我的弹簧配置文件:
<bean id="PaymentService" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition" lazy-init="true">
<property name="schemaCollection">
<bean class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
<property name="inline" value="true" />
<property name="xsds">
<list>
<value>schemas/PaymentServiceOperations.xsd</value>
</list>
</property>
</bean>
</property>
<property name="portTypeName" value="PaymentService" />
<property name="serviceName" value="PaymentService" />
<property name="locationUri" value="/endpoints" />
</bean>
<bean id="bankWebService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
<property name="serviceInterface" value="com.example.stub.PaymentIFBindingSoap" />
<property name="wsdlDocumentUrl" value="https://bank.com/payment.asmx?WSDL" />
<property name="namespaceUri" value="urn:Foo" />
<property name="serviceName" value="PaymentIFBinding" />
<property name="portName" value="PaymentIFBindingSoap" />
</bean>
我的付款服务中的第一个bean,第二个是使用我的银行提供的金融服务的Web服务客户端。
现在我的服务接口及其实现:
@Configurable
public class BankService implements IBankService {
@Autowired
private PaymentIFBindingSoap webService;
}
@Service
public class PaymentService implements IPaymentService {
@Autowired
private IBankService bankService;
}
最后我自己的服务(PaymentService)端点:
@Endpoint
public class PaymentServiceEndpoint {
@Autowired
private IPaymentService paymentService;
}
为了确保一切都清楚,请注意我的端点有一个&#34; PaymentService&#34;的实例。而PaymentService的实例为&#34; BankService&#34;注入自己。
我的理解是一切都应该按计划运行,但是当我尝试将项目部署到tomcat时,我得到了这个例外:
org.springframework.beans.factory.BeanCreationException: 使用名称&#39; paymentServiceEndpoint&#39;创建bean时出错:注入自动有线依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private com.villaparvaneh.services.IPaymentService com.villaparvaneh.services.endpoints.PaymentServiceEndpoint.paymentService;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为&#39; paymentService&#39;的注册自动连接依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private com.villaparvaneh.services.saman.IBankService com.villaparvaneh.services.PaymentService.samanService;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到类型为[com.villaparvaneh.services.saman.IBankService]的限定bean依赖:预期至少有1个bean符合此依赖关系的autowire候选者。依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
我的第一个猜测是,不可能像我在这里做的那样进行嵌套注射,但我找不到支持它的任何东西。
答案 0 :(得分:0)
为什么不将BankService上的注释从Configurable更改为Service。可配置注释用于将依赖注入应用于Spring托管上下文之外的bean,就像您执行“new BankService()”一样。我过去做这项工作的经验很差。如果使用Service注释注释BankService,则组件扫描将实例化它,然后将其注入PaymentService。