社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
简化!
Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。
我使用的是Eclipse的最新的版本:Oxygen。可以访问这个地址来下载:http://www.eclipse.org/downloads/
到此,一个Spring Boot项目配置完毕。
这里只是为了最简单的演示,所以没有加上数据库等其他的设置
package com.martin.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
@Controller
public class HelloWorld {
@RequestMapping("/")
@ResponseBody
public String hello() {
return "Hello World @ " + new Date();
}
}
package com.martin.sbdemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(value = {"com.martin.controller"})
public class SbdemoApplication {
public static void main(String[] args) {
SpringApplication.run(SbdemoApplication.class, args);
}
}
如果要修改服务器端口,数据库等,可以在resource目录下,添加一个配置文件 application.yml
:
server:
port: 8080
当然,你用 application.properties
文件也是可以的,不过 .yml
格式的文件更简洁。
sbdemo
mvn package
,打包target
目录下会生成一个 sbdemo.jar
文件sbdemo.jar
所在目录里,用命令行运行 java -jar sbdemo.jar
http://127.0.0.1:8080
,搞定!阿里云服务器的配置:
- CentOS 7.x
- 安装了JDK 1.8.x
- 开了对应的端口。
sbdemo.jar
到 /usr/
目录下java -jar sbdemo.jar
http://www.your_server_domain.com:8080
,搞定!如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!