I am learning spring and i have a problem that i do not know how to solve.
@Service
@Transactional
public class SchoolService {
@Autowired
private CourseDao courseDao;
@Autowired
private EducationDao educationDao;
@Autowired
private StudentDao studentDao;
@Autowired
private TeacherDao teacherDao;
@Autowired
private StatisticsDao statisticsDao;
............
}
This code is injecting my DAOS into this service class but then i need to inject the class above into two controllers. One way i have tried was with this code but that did not work.
@Autowired
SchoolService sm;
How would i inject it into my controller class. I have tried making the controller class a @Component but nothing seems to work.
ClassPathXmlApplicationContext container = new ClassPathXmlApplicationContext("application.xml");
SchoolService sm = container.getBean(SchoolService.class);
This way works but i do not want to create a new applicationcontext for each time i want to get that bean.
Yes i am using xml at the moment, please don't shoot me :D Thanks.
Try creating the controller bean in the application.xml file instead of annotating the controller.