title: Spring Autowired service is null
body: <p>I have RestController class that calls Presenter to get some data.</p>
  
  <pre><code>@RestController
  @RequestMapping(value="notes/api")
  public class NotesRestController {
  
  private GetAllNotesPresenter getAllNotesPresenter;
  
  @RequestMapping(value="/all")
  public List&lt;Note&gt; getAll(){
      getAllNotesPresenter = new GetAllNotesPresenterImpl();
      return getAllNotesPresenter.getAll();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Inside Presenter class I call DataSource (not Spring Repository, just DAO class).</p>
  
  <pre><code>public class GetAllNotesPresenterImpl implements GetAllNotesPresenter {
  
  private NotesDataSource dataSource;
  private NotesRepository repository;
  
  public GetAllNotesPresenterImpl(){
  
      dataSource = new DatabaseDataSource();
      repository = new NotesRepositoryImpl(dataSource);
  }
  @Override
  public List&lt;Note&gt; getAll() {
      return repository.getAll();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is my Repository class, it is not Spring Repository, it just DAO class.</p>
  
  <pre><code>public class NotesRepositoryImpl implements NotesRepository {
  
  private NotesDataSource dataSource;
  
  public NotesRepositoryImpl(NotesDataSource dataSource){
      this.dataSource = dataSource;
  }
  
  @Override
  public List&lt;Note&gt; getAll() {
      return dataSource.getAll();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is my Service class:</p>
  
  <pre><code>@Service
  @Transactional
  public class NotesServiceImpl implements NotesService {
  
  @Autowired
  private NotesJpaRepository repository;
  
  @Override
  public List&lt;NoteJpa&gt; getAll() {
      return repository.findAll();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Inside DataSource class I want to do @Autowire of Spring service, but I get <strong>null pointer exception.</strong> Service is always null.</p>
  
  <pre><code>@Component
  public class DatabaseDataSource implements NotesDataSource {
  
  @Autowired
  private NotesService notesService;
  
  public DatabaseDataSource(){
  }
  
  @Override
  public List&lt;Note&gt; getAll() {
      return notesService.getAll();
  }
  </code></pre>
  
  <p>}</p>