当前位置: 首页 > news >正文

重庆市建设工程信息网官方网站在线设计平台市场环境

重庆市建设工程信息网官方网站,在线设计平台市场环境,收费网站空间,滨海做网站价格Spring Boot是一个功能强大、灵活且易于使用的框架#xff0c;它极大地简化了Spring应用程序的开发和部署流程#xff0c;使得开发人员能够更专注于业务逻辑的实现。在我们的Spring Boot 3系列之一#xff08;初始化项目#xff09;文章中#xff0c;我们使用了Spring官方…Spring Boot是一个功能强大、灵活且易于使用的框架它极大地简化了Spring应用程序的开发和部署流程使得开发人员能够更专注于业务逻辑的实现。在我们的Spring Boot 3系列之一初始化项目文章中我们使用了Spring官方网站生成的Spring Boot项目作为示例。在该项目中我们可以找到一个名为XjdocApplication的启动类它是Spring Boot应用程序的入口点。本文将详细解释这个启动类的作用和功能。 Spring Boot启动类 在Spring Boot中启动类是整个应用程序的入口点。一般是放在项目的根路径下的推荐放在项目的根路径下。它是一个标注了 SpringBootApplication 注解的 Java 类必须包含一个标准的 main 方法在main方法中添加SpringApplication.run方法用于启动 Spring Boot 应用程序。 import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication public class XjdocApplication {public static void main(String[] args) {SpringApplication.run(XjdocApplication.class, args);} }启动类上边的SpringBootApplication是 注解应用启动的入口类它自动开启了许多有用的特性如自动配置、组件扫描、筹划配置类等从而减少了开发人员的配置工作量。SpringBootApplication是Spring Boot启动类上的核心注解是一个组合注解源码如下 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个注解 SpringBootConfiguration表明被注解的类是一个配置类用于定义应用程序的配置信息。EnableAutoConfiguration开启自动配置功能。ComponentScan启用组件扫描使得Spring能够自动发现和装配一些组件 关系图如下 注解SpringBootConfiguration SpringBootConfiguration 是Spring Boot提供的特定注解之一它用于指示一个类是Spring Boot应用程序的配置类。该注解组合了 Configuration 注解它表示被标注的类可以作为配置类用于配置应用程序的上下文。与 Configuration 注解类似它通常与其他注解一起使用用于定义和管理应用程序的配置信息。源码如下 import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AliasFor; import org.springframework.stereotype.Indexed;Target({ElementType.TYPE}) Retention(RetentionPolicy.RUNTIME) Documented Configuration Indexed public interface SpringBootConfiguration {AliasFor(annotation Configuration.class)boolean proxyBeanMethods() default true; } Configuration 注解源码如下 import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.core.annotation.AliasFor; import org.springframework.stereotype.Component;Target({ElementType.TYPE}) Retention(RetentionPolicy.RUNTIME) Documented Component public interface Configuration {AliasFor(annotation Component.class)String value() default ;boolean proxyBeanMethods() default true;boolean enforceUniqueMethods() default true; }注解EnableAutoConfiguration EnableAutoConfiguration 是Spring Boot框架中的一个重要注解它允许应用程序根据类路径中的依赖自动配置其组件。通过这个注解Spring Boot可以根据应用程序的依赖关系自动配置各种组件。源码如下 import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.context.annotation.Import;Target({ElementType.TYPE}) Retention(RetentionPolicy.RUNTIME) Documented Inherited AutoConfigurationPackage Import({AutoConfigurationImportSelector.class}) public interface EnableAutoConfiguration {String ENABLED_OVERRIDE_PROPERTY spring.boot.enableautoconfiguration;Class?[] exclude() default {};String[] excludeName() default {}; }注解ComponentScan ComponentScan 是Spring框架中的一个注解用于指定Spring在哪些包中寻找组件。它会自动扫描并注册指定包中的所有带有 Component 及其派生注解的类作为Spring的Bean。这样可以方便地将自定义的类纳入Spring的上下文中使得它们可以被自动装配和使用。下面是对 ComponentScan 注解的详细解释 指定扫描包 ComponentScan 注解允许开发人员指定要扫描的包路径。在指定的包及其子包默认当前目录及所有子目录中所有带有 Component 及其派生注解的类都将被自动注册为Spring的Bean这也是推荐把它放在项目根路径下的原因。 自动注册组件 通过 ComponentScan 注解开发人员可以方便地将自定义的类纳入Spring的上下文中使得它们可以被自动装配和使用。这样可以提高开发效率同时减少手动配置的工作量。 定制扫描规则 ComponentScan 注解还支持一些参数配置允许开发人员定制扫描规则如指定特定的注解、过滤规则等以满足特定的需求。 源码如下 import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.core.annotation.AliasFor;Retention(RetentionPolicy.RUNTIME) Target({ElementType.TYPE}) Documented Repeatable(ComponentScans.class) public interface ComponentScan {... }总结 Spring Boot启动类是构建Spring Boot应用程序的关键组成部分。它允许开发人员配置和管理应用程序的行为同时简化了应用程序的配置和部署过程。通过深入了解Spring Boot启动类的功能和用法开发人员可以更好地构建和管理复杂的Spring Boot应用程序。希望本文能够帮助您更好地理解和使用Spring Boot启动类。
http://www.tj-hxxt.cn/news/130716.html

相关文章:

  • 气象网站建设管理总结php网站开发职责
  • 如何做自己公司的网站网站建设优化怎么做
  • 做国外零售的话是在什么网站开店怎样给网站做外链
  • 网页制作与网站建设期末考试注册网站会员会泄露信息吗
  • 烟台网站建设联系电话专业低价建设微网站微商城怎么样
  • 云南建设厅网站职称评定免费建设自己的文学网站
  • 建设地情网站的作用一个网站开发语言
  • 网站规划与建设 pptwordpress 进入
  • 网站设计营销门户网站的推广
  • 个人博客网站html模板wordpress 问答 api
  • 广州网站建设(信科网络)阳区城市规划建设局网站
  • 网站建设与维护课程标准济南公众平台网站建设
  • 网站建设与管理实训报告wordpress的链接功能
  • asp怎么做网站重庆seo关键词排名
  • 网站放到服务器wordpress dux主题首页
  • 贵阳市网站开发建设局网站更改法人所需材料
  • asp.net 如何设置网站首页北京市在建工程项目查询
  • 网站系统制作教程如何用手机开发游戏
  • .net网站开发的例子h5可以做网站吗
  • 门户网站推荐国内网站建设哪家好
  • 如何用服务器搭建网站如何在网上做网站推广
  • 莱州市建设局网站wordpress和dedecms哪个好
  • 网站建设续费是那些充值中心网站怎么做
  • 网站建设往年的高考题推广平台有哪几个
  • 建网站的公司服务中国flash网站模板中心
  • 沈阳网站制作的公司哪家好免费推广的软件
  • 营商环境建设监督局网站安徽公路建设行业协会网站是哪个
  • 沈阳专门代做网站的设计ui
  • 东莞企业网站设计排名软件开发工程师证书怎么考
  • seo网站编辑免费公司网站建站