作者:喵喵的诱惑_204 | 来源:互联网 | 2024-10-21 15:42
代码结构,按照要求新建简单的代码结构
1、在配置类DemoConfig中添加@ComponentScan扫描,可以扫描到加上了Controller、Repository、Service等注解的代码
@Configuration
@ComponentScan(value = "cn.enjoy.*")
public class DemoConfig {}
2、输出扫描到的类
public class DemoApp {public static void main(String[] args){AnnotationConfigApplicationContext applicationContext =
new AnnotationConfigApplicationContext(DemoConfig.class);String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();for(String vo:beanDefinitionNames){System.out.println(vo);}}
}
输出结果
org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
demoConfig
personController
personDao
personImpl
person