我的Action是这样的package fi.finance.web.action;
public class FinanceAction extends ActionSupport {
//注意这里不是接口而是实现类
private CustomerService customerService;
public CustomerService getCustomerService() {
return customerService;
}
public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
}
}
我的applicationContext.xml文件中关于这个action配置是这样的<bean id="customerService" class="fi.customer.service.CustomerService" /><bean id="financeAction" class="fi.finance.web.action.FinanceAction">
<property name="customerService" ref="customerService" />
</bean>但是我在Myeclipse中启动工程是就报错了,错误信息是:Cannot convert value of type [$Proxy15 implementing fi.customer.service.iface.ICustomerService,fi.common.service.iface.IBaseService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [fi.customer.service.CustomerService] for property 'customerService': no matching editors or conversion strategy found我把Action中的private CustomerService customerService;改为private ICustomerService customerService;就好了,为什么注入service的实现类就报错了呢?我原来也只知道要定义接口,但是为什么要定义成接口呢?高手给说下原理,或者给个相关的链接也行还有一点要说的,我把工程弄在Eclipse下,用tomcat启用又不报错,真是郁闷,什么原因啊?
public class FinanceAction extends ActionSupport {
//注意这里不是接口而是实现类
private CustomerService customerService;
public CustomerService getCustomerService() {
return customerService;
}
public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
}
}
我的applicationContext.xml文件中关于这个action配置是这样的<bean id="customerService" class="fi.customer.service.CustomerService" /><bean id="financeAction" class="fi.finance.web.action.FinanceAction">
<property name="customerService" ref="customerService" />
</bean>但是我在Myeclipse中启动工程是就报错了,错误信息是:Cannot convert value of type [$Proxy15 implementing fi.customer.service.iface.ICustomerService,fi.common.service.iface.IBaseService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [fi.customer.service.CustomerService] for property 'customerService': no matching editors or conversion strategy found我把Action中的private CustomerService customerService;改为private ICustomerService customerService;就好了,为什么注入service的实现类就报错了呢?我原来也只知道要定义接口,但是为什么要定义成接口呢?高手给说下原理,或者给个相关的链接也行还有一点要说的,我把工程弄在Eclipse下,用tomcat启用又不报错,真是郁闷,什么原因啊?
解决方案 »
- java 内存地址 通过 jni 能获得到吗 在线等 100分
- 咨询
- 基于RBAC的权限系统 J2EE实现 大家看这样设计表结构合理吗?(急)
- 想请大家出个注意~明天就要上报本科毕业论文的选题了~想写个关于DAO或者工厂模式的
- 我写的javaMail发送邮件在本地windows系统下可以实现,怎么上传到Linux服务器就发送不了邮件了
- HtmlUnit调用javascript
- 高分求助jbuilder8和weblogic7的详细配置文档。
- CMP里使用EJB-QL查询的时候,支持order by吗?????
- 这个程序代码
- 阿里OSS文件上传慢,且不稳定,java,使用官方sdk普通方式上传
- jsp选择文件夹的路径 是文件夹 真的没有一个会的吗 老天呀
- struts2 配置文件中自定义拦截器必须 defaultStack
依赖注入的原理是依托Web容器的,工程启动的时候,通过监听器,然后加载Spring的bean配置文件,然后各种bean的配置的包装方法不同,一般默认的时容器启动时,各个bean被实例化一个,放在容器中,然后有需要调用的时候,都是使用接口引用的setter方法,就是这样。
import java.util.Map;import fi.common.service.iface.IBaseService;
import fi.common.web.Pager;
import fi.customer.bean.IDSCustomer;public interface ICustomerService extends IBaseService<IDSCustomer> {
public long saveCustomer(IDSCustomer customer);
public String getCustomerNumber(long cusotomerId); public void updateCustomer(IDSCustomer customer);
public IDSCustomer findCustomer(Long customerId);}
不定义接口为什么就报错了呢?
这是楼主自己写的有问题吧。 Spring提倡面向接口编程,但是绝对不是强制面向接口编程。
package fi.finance.web.action;
public class FinanceAction extends ActionSupport {
//注意这里不是接口而是实现类
private CustomerService customerService;
public CustomerService getCustomerService() {
return customerService;
}
public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
}
}<bean id="customerService" class="fi.customer.service.CustomerService" />
在Java代码里面没有看到import fi.customer.service.CustomerService;语句,不知道是楼主没有帖上来,还是说CustomerService与FinanceAction在同一个包目录下面呢?
但是我从上面配置与FinanceAction的包目录,明显2个类不同一个包下面。