0

I've been facing the problem of Circular dependency in spring.

Public class UserServiceImpl implements UserService{
   @Autowired
   private RoleService roleService;
}

Public class RoleServiceImpl implements RoleService{
   @Autowired
   private UserService userService;
}

Is there any solution to deal with this problem, But I still want to use @Autowired. Other solutions might be to wire them manually. Or by using bean awares or by using bean post processor.

Suyash Soni
  • 219
  • 2
  • 9
  • Ideally services should not be injected in each other, if you need functionality to two services, they both should be injected in a controller not in each other – ankit Apr 28 '15 at 06:54
  • I know that circular dependencies indicate the bad design and they should be avoided. But in large applications sometimes it's not possible to avoid them. – Suyash Soni Apr 28 '15 at 07:57

1 Answers1

0

The working solution was to add default-lazy-init="true" to the application config xml file

Details are here.

Diptopol Dam
  • 823
  • 1
  • 10
  • 39