Self injection with spring
I tried the following code with Spring 3.x which failed with BeanNotFoundException (exception cause pasted below)
Code:
@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:
Code:
@Service(value = "someService")
public class UserService implements Service{
@Resource(name = "someService")
private Service self;
}
but I couldn't understand how it resolves the cyclic dependency. Anyone?
I tried to search for the documentation but didn't find any(may be I missed), so couldn't able to make out whether this is the feature or bug ;)
Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: 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.Aut owired(required=true)}