Finishing: Notes and description of Springboot

Most article Source https://blog.csdn.net/weixin_41662670/article/details/79649899

Statement bean notes

annotation description
@Component There is no clear correspondence
@Service @Component the subclass, the business logic using Layer (service layer)
@Repository @Component the subclass, the data access using Layer (Layer DAO).
@Controller @Component the subclass, the control layer using the (controller / web) layer

Inject bean notes

annotation description
@Inject 1, @ Inject is the JSR330 (Dependency Injection for Java) specifications, need to import javax.inject.Inject; implemented injection.
2, @ Inject is automatic assembly according to the type, by name if required for assembly, it is necessary with @Named;
. 3, may act on the Inject @ variables, the setter method, constructor,
@Named XX in ( "XXX") @Named is the name of Bean, so the use of @Inject and @Named combination of strategies will automatically injected into byName the transition from byType.
@Autowired 1, @ Autowired spring is carrying annotations, by 'AutowiredAnnotationBeanPostProcessor' class implementation-dependent injection
2, @ Autowired is automatic assembly according to the type, by name if required for assembly, it is necessary with @Qualifier
. 3, there Autowired is @ property is required, can be configured as false, then if configured as false, when the bean is not found in time, the system will not be throwing error
4, @ Autowired can act on the variable, setter method, constructor,
@Qualifier XX in ( "XXX") @Qualifier is the name of Bean, so the use of @Autowired and @Qualifier combination of strategies will automatically injected into byName the transition from byType.
@Qualifier XX in ( "XXX") @Qualifier is the name of Bean, so the use of @Autowired and @Qualifier combination of strategies will automatically injected into byName the transition from byType. But it notes that @Autowired can annotate fields, methods and constructors, and @Qualifier annotation object is a member variable, into the reference method, the constructor parameters.
@Resource 1, @ Resource JSR250 specification is realized, it is necessary to import to realize javax.annotation injection.
2, @ Resource are automatically assembled by name, a name attribute typically specifies 3, @ Resource may act on variables, the setter method.

Notes profile

annotation description
@Configuration Configuration class declaration, equivalent to xml configuration file
@ComponentScan (com.lifeibai) All @Component @Service @Repository @Controller class automatically scan package and the child package, and registered as Bean
@WiselyConfiguration Annotations can be a combination of alternative and @ComponentScan @Configuration
@Bean Used in the method, is declared as a bean, do not write the value, the default name for the bean method names

AOP section Programming notes

annotation description
@Aspect This statement is a section
@After @Before. @Around Definitions section, you can directly blocking rules (entry point PointCut) as a parameter
@PointCut Then call blocking rules specifically defined in @After @Before. @Around in
@Transcational Transaction Processing
@Cacheable Data caching
@EnableAaspectJAutoProxy Spring's support for the open section (Aspect) of
@Target (ElementType.TYPE) Yuan notes, annotations to specify that members of the class of modified -> specifies blocking rules
@Retention(RetentionPolicy.RUNTIME) When the blocking rules annotated as defined @Retention RUNTIME, the annotations can be handled only by the run-time reflection .--> designated

Spring common configuration

annotation description
@import Import configuration class
@Scope New Bean examples
@PostConstruct Executed after executing the constructor
@PreDestroy Bean executed before destruction
@ActiveProfiles Used to declare the activity profile
@profile Providing support to the use of different configurations under different circumstances
@Profile ( "dev") ....... method name dev-xxxx method provides examples of Bean
@EnableAsync Open support for asynchronous tasks (multi-threading)
@Asyns This statement is an asynchronous task, can be declared at the class level and the method level.
@EnableScheduling Open support for the scheduled task (timer)
@Scheduled 声明这是一个计划任务 支持多种计划任务,包含 cron. fixDelay fixRate
@Scheduled (dixedDelay = 5000) 通过注解 定时更新
@Conditional 条件注解,根据满足某一特定条件创建一个特定的Bean
@WebAppCofiguration 指定加载 ApplicationContext是一个WebApplicationContext
@ContextConfiguration 加载配置文件@ContextConfiguration(classes = {TestConfig.class})@ContextConfiguration用来加载ApplicationContext classes属性用来加载配置类
@Value 放置在字段、方法和方法/构造函数参数上,以指定默认值。

 

 

@Value("字符串") -->注入字符串
@Vaule("#{systemProperties['os.name']}")-->注入操作系统属性
@Value ("#{ T (java.lang.Math).random()  * 100.0 }") --> 注入表达式结果  @Value ("#{demoService.another}") --> 注入其他Bean属性  @Value ( "classpath:com/wisely/highlight_spring4/ch2/el/test.txt" )     注入文件资源  @Value ("http://www.baidu.com")-->注入网址资源  @Value ("${book.name}" ) --> 注入配置文件  注意: 使用的是$ 而不是 # 

 


@Enable*注解

注解 描述
@EnableAsync 开启异步任务的支持(多线程)
@EnableScheduling 开启对计划任务的支持(定时器)
@EnableWebMVC 开启对Web MVC 的配置支持
@EnableAaspectJAutoProxy 开启Spring 对 这个切面(Aspect )的支持
@EnableConfigurationProperties 开启对@ConfigurationProperties注解配置Bean的支持
@EnableJpaRepositories 开启对Spring Data JAP Repository 的支持
@EnableTransactionManagement 开启对注解式事物的支持
@EnableCaching 开启注解是缓存的支持.
@EnableDiscoveryClient 让服务发现服务器,使用服务器.Spring cloud 实现服务发现
@EnableEurekaServer 注册服务器 spring cloud 实现服务注册
@EnableScheduling 让spring可以进行任务调度,功能类似于spring.xml文件中的命名空间
@EnableCaching 开启Cache缓存支持

springboot注解

 

注解 描述
@SpringBootConfiguration 包含了@ComponentScan、@Configuration和@EnableAutoConfiguration注解。
@EnableAutoConfiguration 自动配置
@ComponentScan 让spring Boot扫描到Configuration类并把它加入到程序上下文
@PropertySource 是spring3.1开始引入的基于java config的注解。
通过@PropertySource注解将properties配置文件中的值存储到Spring的 Environment中,Environment接口提供方法去读取配置文件中的值,参数是properties文件中定义的key值。
@ConditionalOnBean 当容器里面有指定的 Bean 的条件下
@ConditionalOnClass 当类路径下有指定的类的条件下
@ConditionalOnExpression 基于SpEL表达式作为判断条件
@ConditionalOnJava 基于JVM版本作为判断条件
@ConditionalOnJndi 在JNDI存在的条件下查找指定的位置
@ConditionalOnMissingBean 当容器里没有指定的 Bean 的情况加
@ConditionalOnMissingClass 当类路径下没有指定的类的条件下
@ConditionalOnNotWebApplication 当前项目不是web项目的条件下
@ConditionalOnProperty 指定的属性是否具有指定的值
@ConditionalOnResourcce 类路径下是否有指定的值

Guess you like

Origin blog.csdn.net/jiahao1186/article/details/91972998