Use eclipse to quickly create new spirngboot projects
- 2020-07-21 07:57:12
- OfStack
Share two eclipse ways to create spirngboot projects:
Scenario 1: Create the maven project and modify the pom file
1. Create a simple maven project with eclipse
2. Modify the pom file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.chry</groupId>
<artifactId>studySpringBoot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.7</java.version>
</properties>
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- Package as an executable jar -->
<build>
<finalName>studySpringBoot</finalName>
</build>
</project>
3. Create a new class file
package com.chry.study;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
Description:
1. spring - boot - starter - parent:
The easiest way to manage springboot's official maven management tool is to inherit it. spring-boot-starter-parent contains the following information:
By default, java6 is compiled. If you want to change to java 1.7, add the java.version attribute to pom Use the utf-8 encoding A general testing framework (JUnit, Hamcrest, Mockito) is implemented. Intelligent resource filtering Intelligent plug-in configuration (exec plugin, surefire, Git commit ID, shade).2.spring-boot-starter-web
springboot embedded WEB container, tomcat is not available
Option 2: Install the STS plug-in on eclipse
1, Help -
>
Eclipse Marketplace
Search or select "Popular" TAB, Spring Tool Suite (STS) for Eclipse plug-in, install or Google baidu search
2, new project -
>
Enter spring and you will be prompted to select Spring Starter Project