This article mainly introduces the key points of Spring Boot annotation learning (1). It is very good and has reference value. Friends who need it can refer to it
Annotations for declaring beans:
@Component, a bean without a clear role
@Service, uses
@Repository in the business logic layer (service), and uses
@Controller in the data access layer (dao), Use
@Configuration to declare the configuration class in the presentation layer
No need to add annotations to the entity class, because there is no need to "inject" the entity class
Specify the annotations of the Bean scope :
@Scope("prototype")
The default value is singleton
Optional values prototype, request, session, globalSession
Annotations for declaring the method of generating Bean:
@Bean is used on the method to tell the Spring container that you can get a Bean from the following method
Use the getBean method of the AnnotationApplicationContext object to obtain the Bean
Inject the annotation of the Bean:
@Autowired, automatic injection (default is byType type injection), can be used on attributes or methods. You can set required = "false" to indicate that it is not required to inject multiple implementations of the same interface, by @ qualifier distinguishes
When the injected variable is List and the latter Map, all interface implementations will be injected, Key is the name of the Bean, and value is the implementation class object. You can specify the loading order by adding @order=1 to the implementation class. The smaller the number, the priority is loaded
@Lazy starts delayed injection
Configuration class annotation:
@Configuration declares that the current class is a configuration class, which is equivalent to a xml file configured by Spring
@ComponentScan, which automatically scans all beans under the package name of the configuration class
@ EnableAutoConfiguration, start automatic configuration
In spring boot, these three annotations can be replaced by a @SpringBootApplication
@EnableTransactionManagement, enable transaction support
Transaction management:
@EnableTransactionManagement, added to the configuration class, enables transaction support
@Transactional, added to the Service method, marked as requiring transaction support
AOP annotations:
@AspectJ
Task Scheduling:
@Scheduled用在需要定时执行的方法上 @EnableScheduling用在需要使用的入口类上
Spring MVCIntegration:
First you need to modify the Application class
@SpringBootApplication @EnableTransactionManagement //1、添加继承SpringBootServletInitializer public class Application extends SpringBootServletInitializer{ public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Override //2、重写configure方法 protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return super.configure(builder); } } Spring MVC的注解: @Controller,在展现层使用 @ResponseBody @RestController
[Related recommendations]
1. Special recommendation:"php "Programmer's Toolbox" V0.1 version download
3. JAVA Elementary Introduction Tutorial
The above is the detailed content of Tutorial on java annotation Spring Boot. For more information, please follow other related articles on the PHP Chinese website!

java实现定时任务Jdk自带的库中,有两种方式可以实现定时任务,一种是Timer,另一种是ScheduledThreadPoolExecutor。Timer+TimerTask创建一个Timer就创建了一个线程,可以用来调度TimerTask任务Timer有四个构造方法,可以指定Timer线程的名字以及是否设置为为守护线程。默认名字Timer-编号,默认不是守护线程。主要有三个比较重要的方法:cancel():终止任务调度,取消当前调度的所有任务,正在运行的任务不受影响purge():从任务队

一、@RequestParam注解对应的axios传参方法以下面的这段Springjava代码为例,接口使用POST协议,需要接受的参数分别是tsCode、indexCols、table。针对这个Spring的HTTP接口,axios该如何传参?有几种方法?我们来一一介绍。@PostMapping("/line")publicList

SpringBoot和SpringCloud都是SpringFramework的扩展,它们可以帮助开发人员更快地构建和部署微服务应用程序,但它们各自有不同的用途和功能。SpringBoot是一个快速构建Java应用的框架,使得开发人员可以更快地创建和部署基于Spring的应用程序。它提供了一个简单、易于理解的方式来构建独立的、可执行的Spring应用

随着技术的更新迭代,Java5.0开始支持注解。而作为java中的领军框架spring,自从更新了2.5版本之后也开始慢慢舍弃xml配置,更多使用注解来控制spring框架。

1.Spring项目的创建1.1创建Maven项目第一步,创建Maven项目,Spring也是基于Maven的。1.2添加spring依赖第二步,在Maven项目中添加Spring的支持(spring-context,spring-beans)在pom.xml文件添加依赖项。org.springframeworkspring-context5.2.3.RELEASEorg.springframeworkspring-beans5.2.3.RELEASE刷新等待加载完成。1.3创建启动类第三步,创

作为一名Java开发者,学习和使用Spring框架已经是一项必不可少的技能。而随着云计算和微服务的盛行,学习和使用SpringCloud成为了另一个必须要掌握的技能。SpringCloud是一个基于SpringBoot的用于快速构建分布式系统的开发工具集。它为开发者提供了一系列的组件,包括服务注册与发现、配置中心、负载均衡和断路器等,使得开发者在构建微

SpringBean的生命周期管理一、SpringBean的生命周期通过以下方式来指定Bean的初始化和销毁方法,当Bean为单例时,Bean归Spring容器管理,Spring容器关闭,就会调用Bean的销毁方法当Bean为多例时,Bean不归Spring容器管理,Spring容器关闭,不会调用Bean的销毁方法二、通过@Bean的参数(initMethod,destroyMethod)指定Bean的初始化和销毁方法1、项目结构2、PersonpublicclassPerson{publicP

spring设计模式有:1、依赖注入和控制反转;2、工厂模式;3、模板模式;4、观察者模式;5、装饰者模式;6、单例模式;7、策略模式和适配器模式等。详细介绍:1、依赖注入和控制反转: 这两个设计模式是Spring框架的核心。通过依赖注入,Spring负责管理和注入组件之间的依赖关系,降低了组件之间的耦合度。控制反转则是指将对象的创建和依赖关系的管理交给Spring容器等等。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
