1.修改build.gradle文件,增加spring boot依赖
plugins { id 'java' id 'org.springframework.boot' version '2.3.7.RELEASE' } group 'org.chuck' version '0.0.1' java { sourceCompatibility = JavaVersion.VERSION_1_8 } repositories { maven{ url'http://maven.aliyun.com/nexus/content/groups/public/'} mavenCentral() } dependencies { implementation platform('org.springframework.boot:spring-boot-dependencies:2.3.7.RELEASE') implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-actuator' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } }
2. 增加 application.yml
spring: application: name: test server: port: 8100 servlet: context-path: /${spring.application.name}
参考:https://docs.gradle.org/current/samples/sample_building_spring_boot_web_applications.html