SpringBoot:HelloWorld:修订间差异
imported>Soleverlee 以“=创建maven工程= 修改pom.xml: <source lang="xml" highlight="17-21,29-32"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/X...”为内容创建页面 |
imported>Soleverlee |
||
第39行: | 第39行: | ||
</source> | </source> | ||
=创建Rest服务= | =创建Rest服务= | ||
<source lang="java"> | |||
@Controller | |||
@EnableAutoConfiguration | |||
public class SimpleController { | |||
@RequestMapping("/") | |||
@ResponseBody | |||
String home() { | |||
return "Hello World!"; | |||
} | |||
} | |||
</source> | |||
再创建一个主函数: | |||
<source lang="java"> | |||
public static void main(String[] args) { | |||
SpringApplication.run(SimpleController.class, args); | |||
} | |||
</source> | |||
运行即可(访问localhost:8080): | |||
<pre> | |||
. ____ _ __ _ _ | |||
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ | |||
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ | |||
\\/ ___)| |_)| | | | | || (_| | ) ) ) ) | |||
' |____| .__|_| |_|_| |_\__, | / / / / | |||
=========|_|==============|___/=/_/_/_/ | |||
:: Spring Boot :: (v1.4.0.RELEASE) | |||
... | |||
</pre> | |||
=打包部署= | =打包部署= | ||
[[Category:Programe]] | [[Category:Programe]] |
2016年8月31日 (三) 15:26的版本
创建maven工程
修改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.riguz</groupId>
<artifactId>micrork</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>micrork</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.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
创建Rest服务
@Controller
@EnableAutoConfiguration
public class SimpleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
}
再创建一个主函数:
public static void main(String[] args) {
SpringApplication.run(SimpleController.class, args);
}
运行即可(访问localhost:8080):
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.4.0.RELEASE) ...