• springboot笔记(3) 常用的注解


    1. @Configuration 和 @Bean 来代替xml文件和<bean>

        其中, bean标签的id是@Bean所在的方法名或@Bean的value

    @Configuration的注解类标识这个类可使用Spring IoC容器作为bean定义的来源。

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

          

    (1)建立User类, 

    (2)建立config目录, 在这个目录中, 就相当于建立.xml文件的目录.并注入到ico容器中

        注意: @Bean(name = xx) xx就相当于<bean id="xx"> 

     (3) 建立mapping,映射访问路径

    @Autowired 和@Resource(name="xx")作用一样, 都是定义属性

    (4)访问获取数据

     

    2.@SpringBootApplication注解

       这是组合注解,此注解等同于@Configuration+@EnableAutoConfiguration+@ComponentScan的合集

         (1) @SpringConfiguration注解 说明这是一个配置文件类,它会被@ComponentScan扫描到。进入@SpringBootConfiguration源码发现它相当于                 @Configuration,借此讲解下。

         (2) @EnableAutoConfiguration 自动装配类,

         (3)@ComponentScan: 默认会自动扫描指定包下全部标有@Component的类,并注册成bean,当然包括@Component下的子注解:@Service,                       @Repository,@Controller;默认会扫描当前包和所有子包。

         

  • 相关阅读:
    PerfDog
    adb 常用操作
    netstat命令(net-tools)
    资源路径总结:
    四个作用域对象:
    jsp的 九大内置对象
    Jsp 的语法和指令
    JSP 学习
    server.xml 文件:
    Web.xml 文件使用总结:
  • 原文地址:https://www.cnblogs.com/dangdanghepingping/p/14394989.html
Copyright © 2020-2023  润新知