Spring Boot 快速开始

节选自 《Netkiller Java 手札》

11.2. Spring Boot

11.2.1. 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>api.netkiller.cn</groupId>
	<artifactId>api.netkiller.cn</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>Skyline</name>
	<description>skylinechencf@gmail.com</description>

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

	<build>
		<sourceDirectory>src</sourceDirectory>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.3</version>
				<configuration>
					<source />
					<target />
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>		

11.2.2. Controller

		package hello;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}		

测试

curl http://127.0.0.1:8080/		

原文发布于微信公众号 - Netkiller(netkiller-ebook)

原文发表时间:2016-08-03

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Laoqi's Linux运维专列

MHA快速搭建

2536
来自专栏Petrichor的专栏

shutdown & reboot & last

1473
来自专栏一个会写诗的程序员的博客

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logba...

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Ei...

2745
来自专栏康怀帅的专栏

CoreOS 配置工具 Ignition v2.2

This pre-release version of the specification is experimental and is subject to ...

3526
来自专栏一个会写诗的程序员的博客

$ spring init --list

962
来自专栏数据结构与算法

Codeforce GYM 100741 A. Queries

A. Queries time limit per test 0.25 s memory limit per test 64 MB input st...

28012
来自专栏Java帮帮-微信公众号-技术文章全总结

Java操作数据库Spring(2)

pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www...

3767
来自专栏一个会写诗的程序员的博客

Kotlin Compiler Plugins : All-open , Kotlin-spring,No-arg,Kotlin-jpaCompiler Plugins

Kotlin has classes and their members final by default, which makes it inconvenie...

1532
来自专栏osc同步分享

springMVC 表单校验、日期类型的转换

@Controller @RequestMapping("/appointments") public class AppointmentsController...

3037
来自专栏码匠的流水账

redis的sentinel模式故障演练

redis的sentinel模式相对cluster来说比较简单,缺点是需要浪费一些资源来做sentinel节点,对于中小数据量的业务来说,相对比较划算。

1081

扫码关注云+社区