Springboot中App类的作用
2017-12-10 本文已影响0人
墨色尘埃
/**
* 是Spring Boot项目的核心注解,主要是开启自动配置
*/
@RestController
@SpringBootApplication
@EnableCaching
@ServletComponentScan
@EnableScheduling
public class App {
public static ApplicationContext applicationContext;
@RequestMapping("/")
String home() {
return "Hello Spring Boot";
}
public static void main(String[] args) {
applicationContext = SpringApplication.run(App.class, args);
}
}

基本配置
Spirng boot通常都有一个入口类,入口类一个main方法.
@SpringBootApplication 是Spring Boot的核心注解,并且是一个组合注解
这个注解相当于@Configuration,@EnableAutoConfiguration和@ComponentScan

Spirng boot一些注解解释http://dailycode.daoapp.io/spring-boot-annotations/
@EnableAutoConfiguration 注解会根据类路径中的jar包依赖为当前项目进行自动配置
For example:
添加spring-boot-starter-web依赖,会自动添加tomcat和spring mvc的依赖,那么Spring Boot会对Tomcat和SpirngMVC进行自动配置
修改默认启动图案
在resources下面放一个banner.txt文件


也可以关闭这个图案

Spring Boot配置文件
Spring Boot使用一个全局配置文件,application.properties或application.yml放置在src/main/resources下面或者类路径的/config下面

在默认情况下spring boot 使用/为访问路径 使用8080为 默认端口