I\'ve made a maven project in Spring 3.0, I\'ve made some DAO, services and controllers, in one of mine controller I call a service in which I start a thread, the problem is tha
Spring just autowires beans of the context, no instances created by new. But why do you have declared uService
in AddFriendInMyFriendListTask
and not as a bean property of the outer (bean) class AddFriendInMyFriendListTaskExecutor
, that should simply work:
@Component
public class AddFriendInMyFriendListTaskExecutor {
private class AddFriendInMyFriendListTask implements Runnable {
private final User a;
private final User b;
public AddFriendInMyFriendListTask(User aA, User bB) {
a = aA;
b = bB;
}
public void run() {
AddFriendInMyFriendListTaskExecutor.this.uService.insertRightUserIntoLeftUserListOfFriends(a, b);
}
}
@Autowired
private IUserService uService;
@Autowired
private TaskExecutor taskExecutor;
public void doIt(User a, User b) {
taskExecutor.execute(new AddFriendInMyFriendListTask(a, b));
}
}
(removed some unused getter/setter and made taskExecutor also a bean property)