您的位置:首页 > 教育 > 培训 > 成都手机网站开发_福州网站开发一般多少钱_设计网站的软件_seo项目经理

成都手机网站开发_福州网站开发一般多少钱_设计网站的软件_seo项目经理

2025/4/12 18:38:15 来源:https://blog.csdn.net/qq_22910257/article/details/147140197  浏览:    关键词:成都手机网站开发_福州网站开发一般多少钱_设计网站的软件_seo项目经理
成都手机网站开发_福州网站开发一般多少钱_设计网站的软件_seo项目经理

三、SpringBoot 结构

1.SpringBoot 工作原理

Spring boot应用程序采用各种Starters启动器,入口类是包含@SpringBootApplication注解和main方法的类,然后使用@ComponentScan注解自动扫描项目中的所有组件,并且Spring Boot会根据@EnableAutoConfiguration注解将项目中的依赖项自动配置到应用程序中.例如,如果MySQL数据库在类路径上,但尚未配置任何数据库连接,则Spring Boot会自动配置内存数据库.

2. SpringBoot入口类

Spring Boot应用程序的入口点是包含@SpringBootApplication注解的类,该类中包含运行Spring Boot应用程序的main方法.默认一般是一个* application 结尾。

@SpringBootApplication注解包括自动配置,组件扫描和Spring Boot配置.
如果将@SpringBootApplication注解添加到类中,则无需添加@EnableAutoConfiguration,@ComponentScan和@SpringBootConfiguration注解.@SpringBootApplication注解包括其他所有的注解.

3.常见注解

3.1 @SpringBootApplication

@SpringBootApplication注解是Spring Boot的核心注解,用于标注程序是一个springboot 程序,它是一个组合注解,由多个注解组合而成
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {//此处忽略接口内部内容
}

3.2 @SpringBootConfiguration注解

@SpringBootConfiguration注解可以用Java代码的形式实现spring中xml配置文件配置的效果。也就是用来加载配置文件。
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
public @interface SpringBootConfiguration {
}

3.3 @EnableAutoConfiguration注解

启用自动配置,该注解会使Spring Boot根据项目中依赖的jar包自动配置项目的配置项,这也是 springboot 的核心注解之一,我们只需要将项目需要的依赖包导入进来,它会自动帮我们配置这个依赖需要的基本配置
比如我们的项目引入了spring-boot-starter-web依赖,springboot 会自动帮我们配置 tomcat 和 springmvc

3.4 @ComponentScan 注解

默认扫描@SpringBootApplication类所在包的同级目录以及它的子目录。用来扫描组件和自动装配。

springboot 支持的自动配置可以查看到

在spring-boot-autoconfigure包中包含了支持的自动装配依赖,截图只是其中一部分,我们开发中常见的依赖都做了基本配置

在这里插入图片描述

在这里插入图片描述

4. Springboot 全局配置文件

4.1.格式

​ SpringBoot使用的全局配置文件有两种格式:

​ • application.properties

​ • application.yml

​ 虽然后缀不一样,但是项目中有一个就可以了,yml格式比properties格式的简洁一些。

​ 这个文件的位置在配置文件放在src/main/resources目录或者类路径/config下。

  properties 和 .yml,它们的区别主要是书写格式不同。1).propertiesserver.port=8088server.servlet.context-path=/testboot2).ymlserver:port: 8088servlet:context-path: /testboot另外yml 格式不支持 @PropertySource 注解导入配置 :和值之间有一个空格

4.2.作用

​ 全局配置文件的作用是:可以对一些默认配置值进行修改。

5.starter 启动器

springboot 提供了很多 starter, 可以帮我们快速构建相应的开发环境,导入相关的依赖,并设置相关配置

NameDescriptionPom
spring-boot-starterCore starter, including auto-configuration support, logging and YAML 核心启动器,包括自动配置,日志以及 YAML 支持Pom
spring-boot-starter-activemqStarter for JMS messaging using Apache ActiveMQ 对Apache ActiveMQ提供支持Pom
spring-boot-starter-amqpStarter for using Spring AMQP and Rabbit MQ 对Spring AMQP 和 Rabbit MQ支持Pom
spring-boot-starter-aopStarter for aspect-oriented programming with Spring AOP and AspectJ 对 spring AOP和AspectJ提供支持Pom
spring-boot-starter-artemisStarter for JMS messaging using Apache Artemis 对Apache Artemis提供支持Pom
spring-boot-starter-batchStarter for using Spring BatchPom
spring-boot-starter-cacheStarter for using Spring Framework’s caching supportPom
spring-boot-starter-cloud-connectorsStarter for using Spring Cloud Connectors which simplifies connecting to services in cloud platforms like Cloud Foundry and HerokuPom
spring-boot-starter-data-cassandraStarter for using Cassandra distributed database and Spring Data CassandraPom
spring-boot-starter-data-cassandra-reactiveStarter for using Cassandra distributed database and Spring Data Cassandra ReactivePom
spring-boot-starter-data-couchbaseStarter for using Couchbase document-oriented database and Spring Data CouchbasePom
spring-boot-starter-data-couchbase-reactiveStarter for using Couchbase document-o

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com