******** There is a java web application using Spring Web MVC, when trying to deploy to Tomkat it throws a NoSuchBeanDefinitionException, although the bin is registered in the context of the spring

Class:

package com.freelance.web; import com.freelance.model.Order; import com.freelance.repository.OrderRepository; import com.freelance.service.FreelanceService; import com.freelance.service.FreelanceServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @Controller @RequestMapping("/") public class MainController { **@Autowired private FreelanceService service;** @RequestMapping(method = RequestMethod.GET) public String getHomePage() { return "index"; } @RequestMapping(value = "neworder", method = RequestMethod.GET) public String getOrderPage() { return "neworder"; } @RequestMapping(value = "neworder", method = RequestMethod.POST) public String postOrderPage(@RequestParam("amount") int amount, @RequestParam("phone") String phone) { Order order = new Order(amount, phone); return "neworder"; } } 

spring-config.xml

 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:annotation-config/> <context:component-scan base-package="com.freelance.repository.*" /> <context:component-scan base-package="com.freelance.service" /> <context:component-scan base-package="com.freelance.web"/> <mvc:annotation-driven/> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> <bean id="orderRepository" class="com.freelance.repository.jdbc.JdbcOrderRepository"> </bean> <bean id="freelanceService" class="com.freelance.service.FreelanceServiceImpl" init-method="init"> </bean> <bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/webapp/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans> 

What's wrong?

    1 answer 1

    Add on the field private FreelanceService service; @Qualifier("freelanceService") annotation @Qualifier("freelanceService")