spring注釈開発AnnotationConfigAplicationComptextの使用
2150 ワード
AnnotationConfigApplicationContext Java Spring . application.xml 。 spring , , XML ;
簡単なインターフェースです.public interface outPut {
public void helloworld();
}
実装クラスpublic class outPutImpl implements outPut {
public void helloworld() {
System.out.println("hellworld");
}
}
注の使用は実際にはこれが容器としての役割だと思います.@Configuration
public class hello {
@Bean(name = "helloworl")
public outPut impl() {
return new outPutImpl();
}
}
ここのポイントはClass PathXml Apple Contect()を引用するのではなく、これはxml配置springの使用です.public class Client {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(hello.class);
outPut outPut = (com.spring.lzx.interfacer.outPut) context.getBean("helloworl");
outPut.helloworld();
}
}
を選択します