The auto scan property can be gain through @Component annotation. The same feature you can get through filter the components in the xml configuration file. In this example you will see how to filter the components in Spring framework.
StudentDAO.java
package com.roseindia.student.dao;
import org.springframework.stereotype.Component;
@Component
public class StudentDAO {
@Override
public String toString() {
return " Inside StudentDAO";
}
}
StudentService .java
package com.roseindia.student.services;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.roseindia.student.dao.StudentDAO;
@Component
public class StudentService {
@Autowired
StudentDAO studentDAO;
@Override
public String toString() {
return "StudentService [studentDAO=" + studentDAO + "]";
}
}
AppMain .java
package com.roseindia.common;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.roseindia.student.services.StudentService;
public class AppMain {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "context.xml" });
StudentService stud = (StudentService) context
.getBean("studentService");
System.out.println(stud);
}
}
context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
|
| StudentService [studentDAO= inside StudentDAO] |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.