SpringBoot教程(五)springboot核心注解使用和详细介绍
一.传统Spring中的注解
@Autowired @Repository @service @Component @Controller
在spring中传统注解为 @Repository @Component @service @Controller 使用 @Autowired 进行注入,在 applicationContext.xml中基于XML的bean配置进行注解例如:

二.新版本的Spring注解
@Bean @Configuration
新版本的spring配置bean基于 @Bean 进行配置bean ,@Configuration 对bean进行IOC容器的注入

SpringBootApplication属性由 @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan 构成
SpringBootConfiguration和Configuration一样 ;EnableAutoConfiguration 自动配置spring的上下文,默认会自动根据bean按类型自动配置; ComponentScan 扫描包下的所有bean新增装配 .
SpringBootApplication 因此会作为一个主函数启动 springboot应用;
package com.lpinfo.shop.entity;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class LpinfoShopApplication {
public static void main(String[] args) {
SpringApplication.run(LpinfoShopApplication.class, args);
}
}

浙公网安备 33010602011771号