什么是 JavaConfig?


JavaConfig是Spring3.0新增的概念,就是以注解的形式取代Spring中繁琐的xml文件。

JavaConfig结合了xml的解耦和java编译时检查的优点。

    @Configuration,表示这个类是配置类;
    @ComponentScan,相当于xml的<context:componentScan basepackage=>;
    @Bean,相当于xml的<bean id="student" class="com.guor.entity">;
    @EnableWebMvc,相当于xml的<mvc:annotation-driven>;
    @ImportResource,相当于xml的<import resource="application-context-cache.xml">;
    @PropertySource,用于读取properties配置文件;
    @Profile,一般用于多环境配置,激活时可用@ActiveProfile("dev")注解;

0 0
讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
帮助