In my project I have two servlets and common datasource for both servlets. First servlet is mvc, second is JAXWS. Second servlet have always null for @Autowired fields. My decision for checking this fields for null is so:
public class InRequestServiceImpl implements InRequestService {
@Autowired
public InRequestDao inRequestDao;// = new InRequestDaoImpl();
public InRequestServiceImpl() {
if (inRequestDao == null) inRequestDao = new InRequestDaoImpl();
}
@Override
@Transactional
public void insertData(InRequest doc) throws IOException {
inRequestDao.insertData(doc);
}
...
}
referenced question: SPRING: visibility of autowired beans in services
The question is : is there a good practice for this situation? Help to write clean code.