Issue
@Service
public class UserService implements Service{
@Autowired
private Service self;
}
Does the code above works fine in Spring new versions (5.*)? ( I could check by myself but I wanna know 100%, but myself I may screw it up somehow ) Also I know workarounds:
@Service(value = "someService")
public class UserService implements Service{
@Resource(name = "someService")
private Service self;
}
OR
@Autowired
private ApplicationContext applicationContext;
So I'm not just asking for nothing, I need to know 100% I need an advice from professionals, I don't believe to myself experiments, because I'm not so much experienced in Spring ( e.g. there are much nebulous configs there for me) . Hope this clarifies why I'm asking rather than experiment.
Solution
Ok I found the answer: With Spring 4 it's possible to Self autowired
@Service
@Transactional
public class UserServiceImpl implements UserService{
@Autowired
private UserRepository repository;
@Autowired
private UserService userService;
@Override
public void update(int id){
repository.findOne(id).setName("ddd");
}
@Override
public void save(Users user) {
repository.save(user);
userService.update(1);
}
}
Answered By - J.J. Beam