Eclipse使用maven搭建简单spring boot application Hello World

来源:互联网 发布:控制软件 编辑:程序博客网 时间:2024/06/04 18:43

说明:本例使用spring-boot 2.0.0.BUILD-SNAPSHOT,需要jdk 1.8+版本,maven需要3.2+版本

1、new project,选择Maven Project

2、选择maven-archetype-webapp

3、在pom.xml中添加spring-boot依赖

4、pom.xml文件如下

<?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.zqy</groupId><artifactId>myproject</artifactId><version>0.0.1-SNAPSHOT</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.0.BUILD-SNAPSHOT</version></parent><!-- Additional lines to be added here... --><!-- (you don't need this if you are using a .RELEASE version) --><repositories><repository><id>spring-snapshots</id><url>http://repo.spring.io/snapshot</url><snapshots><enabled>true</enabled></snapshots></repository><repository><id>spring-milestones</id><url>http://repo.spring.io/milestone</url></repository></repositories><pluginRepositories><pluginRepository><id>spring-snapshots</id><url>http://repo.spring.io/snapshot</url></pluginRepository><pluginRepository><id>spring-milestones</id><url>http://repo.spring.io/milestone</url></pluginRepository></pluginRepositories><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></project>

5、新建Example类

6、Example类代码如下:

package myproject;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@EnableAutoConfigurationpublic class Example {@RequestMapping("/")String home() {return "Hello World!";}public static void main(String[] args) throws Exception {SpringApplication.run(Example.class, args);}}
7、运行main方法,启动project

8、启动成功,浏览器中访问:localhost:8080



阅读全文
0 0
原创粉丝点击