Reputation: 161
I am using autowired annotation for the dependency injection in my app. How can I avoid cyclic dependency while using constructor injection.
public interface CustomUserRepository {
void myCustom();
}
public interface UserRepository extends CustomUserRepository {
----
}
public class UserRepositoryImpl implements CustomUserRepository {
@Autowired UserRepository self; //Here I have the Cyclic dependency
}
Upvotes: 1
Views: 524
Reputation: 28756
Spring does not support cyclic dependencies with constructor injection. The rationale is that an object must be fully initialized before it can be injected.
To resolve the issue make your circular dependency into a property.
Upvotes: 1