环境约束

–jdk1.8:Spring Boot 推荐jdk1.7及以上;java version "1.8.0_112"

–maven3.x:maven 3.3以上版本;Apache Maven 3.3.9

–IntelliJIDEA2017:IntelliJ IDEA 2017.2.2 x64、STS

–SpringBoot 1.5.9.RELEASE:1.5.9;

1、MAVEN设置;

给maven 的settings.xml配置文件的profiles标签添加
<profile>
  <id>jdk-1.8</id>
  <activation>
    <activeByDefault>true</activeByDefault>
    <jdk>1.8</jdk>
  </activation>
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
  </properties>
</profile>

Idea file-new file-spring initializr

选择jdk版本 1.8,然后下一步 输入项目信息

下一步,选择最简单的web

下一步,输入项目名,选择项目在本地保存的位置

最后finish 完成项目构建。

代码部分:

 POM.XML 引入spring-boot 需要的依赖和maven打包的插件,代码如下:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

新建一个class作为spring-boot的启动类,代码如下:

@SpringBootApplication
public class HelloWorldMainApplicaion {

    public static void main(String[] args) {

        SpringApplication.run(HelloWorldMainApplicaion.class,args);
    }

}

新建一个controller,代码如下:

@Controller
public class HelloController {

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return "Hello World";
    }
}

 启动项目:

浏览器访问刚刚的项目:http://localhost:8080/hello

 

GitHub 加速计划 / sp / spring-boot
37
6
下载
spring-projects/spring-boot: 是一个用于简化Spring应用开发的框架。适合用于需要快速开发企业级Java应用的项目。特点是可以提供自动配置、独立运行和内置的Tomcat服务器,简化Spring应用的构建和部署。
最近提交(Master分支:16 天前 )
1cd14c96 Prior to this commit, Spring Boot would use Framework's `Jackson2ObjectMapperBuilder` to configure the `ObjectMapper` instance. This builder would configure the `ProblemDetail` mixin automatically. With the introduction of Jackson 3.x support, Spring Framework removed its builder in favor of the native Jackson builder. As a result, the mixin is not registered with the `JsonMapper` aymore. This commit ensures that the mixin is registered if the `ProblemDetail` class is present in the classpath. Closes gh-47298 10 小时前
51b606e9 - 11 小时前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐