Java Config 注解
java config 是指基于 java 配置的 spring。传统的 Spring 一般都是基本 xml 配置的,后来 spring3.0 新增了许多 java config 的注解,特别是 spring boot,基本都是清一色的 java config。
@Configuration
在类上打上这一标签,表示这个类是配置类
@ComponentScan
相当于 xml 的 <context:componentscan basepakage=>
@Bean
bean 的定义,相当于 xml 的
<bean id="objectMapper" class="org.codehaus.jackson.map.ObjectMapper" />
@EnableWebMvc
相当于 xml 的 <mvc:annotation-driven>
@ImportResource
相当于 xml 的 <import resource="applicationContext-cache.xml">
@PropertySource
spring 3.1 开始引入,它是基于 java config 的注解,用于读取 properties 文件
@Profile
spring3.1 开始引入, 一般用于多环境配置,激活时可用 @ActiveProfiles 注解,@ActiveProfiles("dev")
等同于 xml 配置
<beans profile="dev"> <bean id="beanname" class="com.pz.demo.ProductRPC"/> </beans>
激活该 profile spring.profiles.active, 也可设置默认值 spring.profiles.default
<context-param> <param-name>spring.profiles.default</param-name> <param-value>dev</param-value> </context-param>