SpringBoot 环境搭建
Posted 皓月行空
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot 环境搭建相关的知识,希望对你有一定的参考价值。
环境 :
jdk1.7
myeclipse2014
springboot
springboot 官网指南:https://spring.io/guides/gs/spring-boot/
1、使用maven构建java project
2、修改pom文件:
<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.zxl.test</groupId>
<artifactId>springboot-increase</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>springboot-increase</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
主要是添加红色部分的内容。
3、创建Controller类HelloController
package hello;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController
@RequestMapping("/")
public String index()
return "Hello World!";
4、创建启动类Application
package hello;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class Application
public static void main(String[] args)
SpringApplication.run(Application.class, args);
6、启动Application
Application.java文件上右键 run as --》 java application
控制台输出如下:
7、打开浏览器,输入 localhost:8080,页面显示Hello World
以上是关于SpringBoot 环境搭建的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot.01.SpringBoot概述及基本环境搭建