您的位置:首页 > 编程语言 > Java开发

SpringBoot

2016-06-22 15:54 323 查看
Spring Boot提供了一个强大的一键式Spring的集成开发环境,能够单独进行一个Spring应用的开发,其中:

(1)集中式配置(application.properties)+注解,大大简化了开发流程

(2)内嵌的Tomcat和Jetty容器,可直接打成jar包启动,无需提供Java war包以及繁琐的Web配置

(3)提供了Spring各个插件的基于Maven的pom模板配置,开箱即用,便利无比。

(4)可以在任何你想自动化配置的地方,实现可能

(5)提供更多的企业级开发特性,如何系统监控,健康诊断,权限控制

(6) 无冗余代码生成和XML强制配置

(7)提供支持强大的Restfult风格的编码,非常简洁

开发SpringBoot项目:

1. 创建Maven项目

2. 添加SpringBoot jar包依赖

3. 编写接口

4. 发布程序

5. 访问接口

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>
<!-- 项目名称,由于有的项目并不是一个jar包构成的,而是由很多的jar包组成的。因此这个groupId就是整个项目的名称。 -->
<groupId>com.test</groupId>
<!-- 包的名称 -->
<artifactId>maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 包的类型,一般都是jar,也可以是war之类的。如果不填,默认就是jar -->
<packaging>jar</packaging>

<name>maven</name>
<!-- maven的地址 -->
<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.2.3.RELEASE</version>
</parent>
<dependencies>
<!--junit jar依赖 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<!--SpringBoot jar依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
</dependencies>

</project>


测试

package com.test.maven;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@EnableAutoConfiguration
public class TestController {
@RequestMapping(value ="/hello", method = RequestMethod.GET)
@ResponseBody
public String hello(){
return "你好  hello world";
}

//发布程序
public static void main(String[] args) {
SpringApplication.run(TestController.class, args);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: