spring注解开发
1、
@Configuration是标注配置文件,@ComponentScan(value = "com.wsd")扫描哪些包可以加入容器,默认control、service、compcont、prepertity注解可以
@Configuration @ComponentScan(value = "com.wsd") public class Myconfig { // @Bean // public Person person() { // return new Person("hehehehe"); //} }
2、AnnotationConfigApplicationContex 和classpathapplicationcontext是ApplicationContex和子类,具有不同功能
public class App
{
public static void main( String[] args )
{
AnnotationConfigApplicationContext ap= new AnnotationConfigApplicationContext(Myconfig.class);
String[] strings=ap.getBeanDefinitionNames();
for (int i = 0; i < strings.length; i++) {
System.out.println(strings[i]);
}
}
}