spring boot hello world
本文讲解初始用户搭建spring boot 工程。
新建工程目录结构:
application.java放在最外层的包目录里

先添加pom.xml的依赖包:
<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.test.my</groupId> <artifactId>testApplication</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>testApplication</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <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> </project>
application.java内容:
package com.test.my.testApplication; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
HelloController.java
package com.test.my.testApplication.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/api") public class HelloController { @RequestMapping(value="/hello",method=RequestMethod.GET) public String hello() { return "hello world"; } }
application.properties:
只需添加工程对应的端口号
server.port=8080
浏览器访问:http://localhost:8080/api/hello

posted on 2017-12-27 18:17 yang.scofield 阅读(161) 评论(0) 收藏 举报
浙公网安备 33010602011771号