I have the following AccountController class
@Controller
@RequestMapping("/rest/accounts")
public class AccountController {
private AccountService accountService;
@Autowired
public AccountController(AccountService accountService) {
this.accountService = accountService;
}
... implemented methods here
}
The AccountService class is as below
public interface AccountService {
public Account findAccount(BigInteger id);
public Account createAccount(Account data);
public Account deleteAccount(String email);
public Boolean updateAccount(String email,String password);
public List<Account> findAllAccounts();
// public Account deleteAccount();
public Customer createCustomer(String accountId, Customer data);
public List<Customer> findCustomersByAccount(String accountId);
}
The AccountServiceImpl class is as below
@Service
public class AccountServiceImpl implements AccountService{
@Autowired
private AccountRepository accountRepo;
@Autowired
private CustomerRepository custRepo;
..implemented methods here
}
My servlet.xml has the following component scan
<context:component-scan base-package="com.sam.spring.web.rest.mvc" />
The /src/resource/context.xml has the following
<context:component-scan base-package="com.sam.spring.web.core.services"></context:component-scan>
<context:component-scan base-package="com.sam.spring.web.core.repositories.jpa"></context:component-scan>
I get the following error:
org.springframework.beans.factory.BeanCreationException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountController' defined in file ...
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.sam.spring.web.core.services.AccountService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
What have I done wrong in this setup ?
Try this <context:component-scan base-package="com.sam.spring.web.rest.mvc, com.sam.spring.web.core.services, com.sam.spring.web.core.repositories.jpa" />