SpringBoot

来源:互联网 发布:docker连接外部数据库 编辑:程序博客网 时间:2024/04/26 18:13

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@EnableAutoConfigurationpublic 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);    }}
0 0
原创粉丝点击