注解说明

因为对于一些注解不太了解,做下记录说明

======================================================================

1、@Bean:告诉Spring,一个带有@Bean的注解方法将返回一个对象,该对象应该被注册为在Spring应用程序上下文中的bean。

2、@Configuration::一般标识在类上,表明这个类将作为springBean注入到Spring IoC容器。

例如:

<beans>  

    <bean id = "car" class="com.test.Car">   

        <property name="wheel" ref = "wheel></property>  

    </bean>   

    <bean id = "wheel" class="com.test.Wheel"></bean>  

</beans>  

相当于:

@Configuration  
public class Conf {  
    @Bean  
    public Car car() {  
        Car car = new Car();  
        car.setWheel(wheel());  
        return car;  
    }  
    @Bean   
    public Wheel wheel() {  
        return new Wheel();  
    }  

3、@EnableAutoConfiguration:自动配置spring的上下文,猜测和配置你想要的bean类,通常会自动根据你的类路径和你的bean定义自动配置。

4、@ComponentScan:会自动扫描指定包下的全部标有@Component的类,并注册成bean,当然包括@Component下的子注解@Service,@Repository,@Controller。

5、@SpringBootApplication = @Configuration + @EnableAutoConfiguration + @ComponentScan。(用于标识SpringBoot启动类)

6、@ConfigurationProperties(prefix="my"):将前缀为"my"的属性注入进配置类对应属性上(赋值)。

7、@EnableConfigurationProperties:使@ConfigurationProperties生效。

8、@Inherit:一般加在父类注解上面,以便一个子类想获取到父类上的注解信息。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值