The meaning of annotations added on Application

Example

import com.lenovo.platform.util.PrintApplicationInfo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.RestController;

@EnableDiscoveryClient // 作为微服务,能够发现服务器并自动注册
@EnableFeignClients // 能够扫描@FeignClient注解,实现feign API 调用

@RestController // 本类可成为Controller组件,返回类型为responseBody
@MapperScan({
    
    "com.lenovo.**.mapper"}) // 配置扫描mapper包范围
@ServletComponentScan // 能够扫描@WebServlet/@WebFilter/@WebListener三个注解标记的Servlet组件

@EnableAsync // 能够实现方法异步调用
@EnableScheduling // 能够实现方法定时任务
@EnableTransactionManagement // 能够使方法通过注解实现事务

@EnableConfigurationProperties // 能发现@ConfigurationProperties注解,实现自动获取application中配置的属性
@EnableCaching // 能够实现组件缓存和接口缓存(@Cacheable(cacheNames = "studentCache", key = "#studentId"))
//@EnableAdminServer // 开启Eureka 对 springBoot 项目的端点监控

@SpringBootApplication(scanBasePackages = "com.lenovo.**") // springboot启动类注解,标记该类能够配置其他的相关注解、配置组件扫描包范围;
public class Application {
    
    

    public static void main(String[] args) {
    
    
        // 启动spring-boot项目
        ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
        // 打印项目信息
        PrintApplicationInfo.print(context);
    }
}

Guess you like

Origin blog.csdn.net/leinminna/article/details/112798994