侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Spring Boot (一) Hello world

2023-12-19 星期二 / 0 评论 / 0 点赞 / 135 阅读 / 3094 字

关键pom配置 <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</a

关键pom配置

<parent>		<groupId>org.springframework.boot</groupId>		<artifactId>spring-boot-starter-parent</artifactId>		<version>1.4.1.RELEASE</version>		<relativePath/> <!-- lookup parent from repository -->	</parent><dependency>			<groupId>org.springframework.boot</groupId>			<artifactId>spring-boot-starter-web</artifactId>		</dependency><plugins>			<plugin>				<groupId>org.springframework.boot</groupId>				<artifactId>spring-boot-maven-plugin</artifactId>			</plugin>		</plugins>

hello world

@SpringBootApplicationpublic class DemoApplication {	public static void main(String[] args) {		SpringApplication.run(DemoApplication.class, args);	}}

@SpringBootApplication背后

@java.lang.annotation.Target({java.lang.annotation.ElementType.TYPE})@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)@[email protected]@org.springframework.boot.SpringBootConfiguration@org.springframework.boot.autoconfigure.EnableAutoConfiguration@org.springframework.context.annotation.ComponentScan(excludeFilters = {@org.springframework.context.annotation.ComponentScan.Filter(type = org.springframework.context.annotation.FilterType.CUSTOM, classes = {org.springframework.boot.context.TypeExcludeFilter.class})})

SpringBootConfiguration背后

@java.lang.annotation.Target({java.lang.annotation.ElementType.TYPE})@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)@java.lang.annotation.Documented@org.springframework.context.annotation.Configuration

EnableAutoConfiguration背后

@java.lang.annotation.Target({java.lang.annotation.ElementType.TYPE})@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)@[email protected]@org.springframework.boot.autoconfigure.AutoConfigurationPackage@org.springframework.context.annotation.Import({org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector.class})

最关键的三个注解

@Configuration

是javaConfig形式的spring配置

@EnableAutoConfiguration

借助@Import,将所有符合自动配置条件的bean定义加载到IoC容器中

SpringFactoriesLoader是Spring框架的扩展方案,配置文件是META-INF/spring.factories

在EnableAutoConfiguration中,提供了一种配置查找的功能支持,查找所有classpath中的META-INF/spring.factories配置文件,通过配置项反射为javaConfig,配置IoC容器

@ComponentScan

自动扫描并加载符合条件的组件或bean定义,并加载到容器中

广告 广告

评论区