SPRING MVC - 自动装配的bean出错

时间:2016-03-30 23:49:31

标签: spring-mvc autowired

我有这个maven项目及其模块

| _____模型

| _____持久性

| _____服务

         |_ service-context.xml

| _____视图

         |_ spring/app-config.xml

我有这个控制器 “视图”模块中的controllers.HomeController

@Controller

public class HomeController {

protected final Log logger = LogFactory.getLog(getClass());

private IServicioService servicioService;

@RequestMapping(value="/home.htm")
public ModelAndView handleRequest(HttpServletRequest request,  HttpServletResponse response)
        throws ServletException, IOException {

    logger.info("Returning hello view");

    return new ModelAndView("home.jsp");
}

@Autowired
public void setServicioService(IServicioService servicioService) {
    this.servicioService = servicioService;
}

我的服务模块中的服务servicios.ServicioService

@Service
public class ServicioService implements IServicioService{

private ServicioDao servicioDao;

public ServicioService(){}

/*************************** Gett&Sett ****************************/

public ServicioDao getServicioDao() {
    return servicioDao;
}

public void setServicioDao(ServicioDao servicioDao) {
    this.servicioDao = servicioDao;
}

}

IServicioService没有@Service ServicioService bean在service-context.xml中定义,如

<bean id="servicioService" class="servicios.ServicioService">
    <property name="servicioDao"   ref="servicioDao" />
</bean>

**我的app-config.xml正在导入service-context.xml **

   <import resource="classpath*:service-context.xml" />
   <context:component-scan base-package="controllers" />

Idk为什么要给我这个

找不到类型为[servicios.ServicioService]的匹配bean用于依赖:预期至少有一个bean可以作为此依赖项的autowire候选者。依赖注释:{}

帮助!!

1 个答案:

答案 0 :(得分:1)

您的问题可能在于xml配置。 尝试添加app-config.xml行:

<context:component-scan base-package="servicios" />

之后你应该对你的daos做同样的事情