【发布时间】:2011-12-15 14:21:37
【问题描述】:
我的任务是更新一个我没有编写的旧项目。
该项目基于 Spring MVC,并且具有我不熟悉的旧 Spring Controller 配置。
控制器的bean配置如下
<bean id="controllerName" class="the.project.controller.class">
<property name"serviceName">
<ref bean="serviceName">
</property>
<property name"successView">
<value>viewName</value>
</property>
</bean>
其中serviceName指的是一个用@Service注解的类,如下
@Service(value=serviceName)
这是 xml 配置的正确替换吗?
@Autowired
@Qualifier("serviceName")
ServiceNameImpl serviceName
谢谢
这里编辑的是serviceName类和接口的组织方式
public interface ServiceName {
// methods omitted
}
@Service(value="serviceName")
public class ServiceNameImpl implments ServiceName {
//methods omitted
}
@Resource 注释对我不可用(Spring 3.0.7)并且上面的 Autowire 失败(因为它看起来不像预期的类型,如下所述)
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching beans of type [the.project.ServiceNameImpl] found for dependency
鉴于编辑,我在这里做错了什么(抱歉遗漏此信息)?
最后我需要能够访问接口的方法及其实现
例如
serviceName.doSomething(someVar);
【问题讨论】:
标签: java spring spring-mvc annotations