I tried the following code with Spring 3.x which failed with BeanNotFoundException
and it should according to the answers of a question which I asked before - Can I inject same class using Spring?
@Service
public class UserService implements Service{
@Autowired
private Service self;
}
Since I was trying this with Java 6, I found the following code works fine:
@Service(value = "someService")
public class UserService implements Service{
@Resource(name = "someService")
private Service self;
}
but I don't understand how it resolves the cyclic dependency.
EDIT:
Here's the error message. The OP mentioned it in a comment on one of the answers:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.spring.service.Service] 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)}