how can I access to exampleService from the thread ? In new thread is null. ExampleService is an annotated @Service class. SessionFactory I set from dao and it is no null.
public class ExampleInterceptor extends EmptyInterceptor {
private Logger logger = Logger.getLogger(getClass());
private static final long serialVersionUID = 1L;
@Autowired
SessionFactory sessionFactory;
@Autowired
ExampleService exampleService;
public void setExampleService(ExampleService exampleService) {
this.exampleService = exampleService;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public void afterTransactionCompletion(Transaction tx) {
new Thread(new SimpleThread(exampleService)).start();
}
protected class SimpleThread implements Runnable {
protected ExampleService exampleService;
public SimpleThread() {
};
public SimpleThread(ExampleService exampleService) {
this.exampleService = exampleService;
}
@Override
public void run() {
exampleService.method(); // is null at this location
}
}
}