Spring3dependency injection无法使用mule

我无法在CustomerServiceImpl服务类中的引用变量中注入customerDao对象。

这是我的mule_flow.mflow文件

                

这是我的Spring-mule.xml文件

            classpath:hibernate.cfg.xml   org.hibernate.cfg.AnnotationConfiguration    org.hibernate.dialect.Oracle10gDialect true org.hibernate.cache.NoCacheProvider auto                   

这是我的CustomerServiceImpl.java

 package com.proj.pos.webservice.implementation; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import com.proj.pos.dao.interfac.CustomerDao; import com.proj.pos.entity.Customer; import com.proj.pos.webservice.interfac.CustomerService; @WebService(endpointInterface = "com.proj.pos.webservice.interfac.CustomerService", serviceName = "CustomerService") public class CustomerServiceImpl implements CustomerService { public CustomerDao getCustomerDao() { return customerDao; } public void setCustomerDao(CustomerDao customerDao) { this.customerDao = customerDao; } @Autowired private CustomerDao customerDao;//not getting populated.tried removing autowired as well. @Transactional @WebMethod(operationName="addCustomer") @WebResult(name="addCustomerResult") @Override public Customer addCustomer(@WebParam(name="customerId")long customerId,@WebParam(name="fname")String fname,@WebParam(name="lname")String lname,@WebParam(name="age")long age,@WebParam(name="dateOfBirth")String dateOfBirth,@WebParam(name="address")String address) { Customer customer=new Customer(customerId, fname, lname, age, dateOfBirth, address); customer.setCustomerId(customerDao.persist(customer));//throws NUllPointerException here as customerDao is null.. return customer; } } 

知道DI不工作的原因吗?

你可能遗漏了几件事:

  1. 您应该扫描您想要弹簧的包以查看带注释的类。 在您的情况下,您应该将以下xml片段添加到您的mule配置
  2. 您应该将组件声明为spring对象而不是组件,因此应将替换为