---
title: "cxf  spring注入"
author: "hotsmile"
date: "2014-03-29T22:26:33Z"
tags: ["Spring", "cxf"]
categories: ["企业架构"]
slug: "cxf-spring"
draft: false
lastmod: "2014-03-29T22:26:33Z"
id: 2038334
url: "https://hotsmile.iteye.com/blog/2038334"
---

@WebService  
public class DeviceService implements IDeviceService{  
   @Autowired  
   private IAccountManager accountManager;

   private Account findUserByUsername(String username){  
  return accountManager.findAccountByUserName(username);  
   }  
}

 

 

当调用private IAccountManager accountManager，如果没有正确配置，会报错，没有注入，造成抛空指针的错误。

 

解决了， sping集成cxf的时候注入sping管理的bean的时候比如说service层，用annotation标注了@Service

&lt;bean id="dvrService" class="com.zhaohai.automation.device.webservice.DvrServiceImpl"&gt;  
     &lt;property name="accountManager"&gt;  
  &lt;ref bean="accountManagerImpl"/&gt;  
     &lt;/property&gt;  
&lt;/bean&gt;