1 Star 0 Fork 0

chengxiang92 / note

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SpringBoot.md 1.76 KB
一键复制 编辑 原始数据 按行查看 历史
chengxiang92 提交于 2021-05-24 23:40 . springboot

SpringBoot

原理

自动配置

pom

  • spring-boot-dependencies 核心依赖在父工程中

启动器

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

springboot的启动场景

主程序

@SpringBootApplication
public class KeerApplication {

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

}

注解

@SpringBootConfiguration		//springboot的配置
		@Configuration					//spring配置
				@Component					//spring组件 
@EnableAutoConfiguration		//自动配置
		@AutoConfigurationPackage		//自动配置包
				@Import({Registrar.class})		//自动配置‘包注册’
		@Import({AutoConfigurationImportSelector.class})	//自动配置导入选择
				List<String> configurations = this.getCandidateConfigurations(annotationMetadata, attributes);

META-INF/spring.factories //自动配置核心文件

配置

异步任务

@EnableAsync	//开启异步注解

@Async		//异步注解

邮件任务

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-mail</artifactId>
</dependency>
@Autowired
JavaMailSenderImpl mailSender;

//简单邮件
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setSubject("title");
mailMessage.setText("text");
mailMessage.setTo("xx@mail.com");
mailMessage.setFrom("xx@mail.com");
mailSender.send(mailMessage);

定时任务

TaskScheduler	//任务调度
TaskExecutor //任务执行
  
@EnableScheduling		//开启定时功能的注解
@Scheduled					//什么时候执行
  
cron //表达式
1
https://gitee.com/chengxiang92/note.git
git@gitee.com:chengxiang92/note.git
chengxiang92
note
note
main

搜索帮助