Mega Code Archive
BeanName Aware
File: context.xml
File: Main.java
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
public class Main {
public static void main(String[] args) throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(
new ClassPathResource("context.xml"));
LoggingBean lb = (LoggingBean) factory.getBean("logging");
lb.run();
}
}
class LoggingBean implements BeanNameAware {
private String name;
public void setBeanName(String name) {
this.name = name;
}
public void run() {
System.out.println("Bean name is'" + this.name + "'.");
}
}