Getting error
No matching bean of type [foo.bar.service.AccountService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
my service:
public interface AccountService {
@Service
public class AccountServiceImpl implements AccountService {
So I should get the implementation
Where I am trying to get it :
public class CustomAuthentication implements AuthenticationProvider {
@Autowired
private AccountService accountService;
In my other class also doing same thing, but there it works.
@Controller
public class AccountController {
@Autowired
private AccountService accountService;
When I remove the those 2 lines from my CustomAuthentication, getting no errors.
configuration just incase:
<context:component-scan base-package="foo.bar" />
Only a spring managed object can Autowire another component/service/repository.
public class CustomAuthentication implements AuthenticationProviderneed to be spring managedlike
Try annotating the CustomAuthenitcation with @Component
and let me know how CustomAuthentication Object is created. CustomAuthentication object should be a proxy obtained by requesting to Spring(ApplicationContext.getBean() or autowired in another bean).
UPDATE:
reason for this error is you have two config files. spring-servlet.xml and spring-security.xml. Beans defined in spring-security.xml is not able to find those in other.
so you should try something like
<import resource="spring-servlet.xml"/>inspring-security.xml.