Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”
The cause of
Mainly engaged in Android development partners, occasionally back-end development, because Android Studio is a sub-system of Idea, you can directly use Studio for development, no need to download Idea tools
Configure the environment
- Android Studio
- Jdk8
- Gradle – 6.1.1
Fast integration with SpringBoot project
- The first step
Go to start.spring. IO/download and start the demo. What I selected here is that the Gradle project Java language has added web dependency
-
The second step is to open the Demo project and modify the Gradle properties file
This step is not necessary. I use the all version. To save network resources, I use the all version directly
3. Step 3 Adjust the build.gradle file as shown in the following example
Buildscript {ext {springIOVersion = '1.0.10.RELEASE' springBootVersion = '1.5.9.RELEASE'} Repositories {mavenLocal() mavenCentral() maven { url "http://repo.spring.io/release" } maven { url "http://repo.spring.io/milestone" } maven { url "http://repo.spring.io/snapshot" } maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath "io.spring.gradle:dependency-management-plugin:${springIOVersion}" classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" } } plugins { id 'org.springframework.boot' Version '1.5.9.RELEASE'// synchronization project prompt not found If direct comment does not impact startup cannot use plug-in package RELEASE id 'io.spring.dependency-management' version '1.0.0.release' Id 'Java'} group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '1.8'// The default demo uses JDk11 MavenCentral () mavenCentral() maven{url ('http://maven.aliyun.com/nexus/content/groups/public/') } google() jcenter() } dependencies { compile 'org. Springframework. The boot: spring - the boot - starter: 2.3.4. The RELEASE of' the compile 'org. Springframework. The boot: spring - the boot - starter - web: 2.3.4. RELEASE'/pack/implementation dozen don't come in Temporarily not found reasons to switch to test the compile} { useJUnitPlatform() }Copy the code
- Step 4 write interface tests
Note that the Controller package is in the same directory or subpackage as the bootstrap class@Controller
public class QuickStartController {
@RequestMapping("/quick")
@ResponseBody
public String quick(a){
return "hello SpringBoot !"; }}Copy the code
5. Step 5 Start the springBoot project
Run the main method of the boot class and observe the logsTomcat started on port(s): 8080 (http)With the context path 'shows that the project published to port 8080, virtual path is empty, the browser to access the HTTP: localhost: 8080 / quickCopy the code
At this point, we’re done