内容简介:Spring Initializr它允许您从非常简单的UI创建各种基于Spring Boot的应用程序。您可以引导的一些类型的应用程序是:Spring Boot提供了大量的入门项目。Spring Initializr支持所有这些以及更多。各种初级项目和支持的选项包括:
Spring Initializr http://start.spring.io/ 是引导Spring Boot项目的绝佳工具。
它允许您从非常简单的UI创建各种基于Spring Boot的应用程序。您可以引导的一些类型的应用程序是:
- Web应用程序
- Restfu的应用程序
- Batch批量处理
Spring Boot提供了大量的入门项目。Spring Initializr支持所有这些以及更多。各种初级项目和支持的选项包括:
- spring-boot-starter-web-services:用于构建公开SOAP Web服务的应用程序
- spring-boot-starter-web - 构建Web应用程序和RESTful应用程序
- spring-boot-starter-test - 编写出色的单元和集成测试
- spring-boot-starter-jdbc - 传统的JDBC应用程序
- spring-boot-starter-hateoas - 通过添加HATEOAS功能使您的服务更加RESTful
- spring-boot-starter-security - 使用Spring Security进行身份验证和授权
- spring-boot-starter-data-jpa - 带有Hibernate的Spring Data JPA
- spring-boot-starter-cache - 启用Spring Framework的缓存支持
- spring-boot-starter-data-rest - 使用Spring Data REST公开简单REST服务
在本指南中,我们考虑使用Spring Initializr创建一个简单的Web应用程序。
使用Spring Initializr创建Web应用程序非常简单。
如上图所示,必须执行以下步骤
- 启动Spring Initializr http://start.spring.io/ 并选择以下内容
- 输入你的组名:com.xxx.springboot组名
- 选择xxx-services为脚手架Artifact
- 选择以下依赖项
- Web
- 如果希望使用数据库JPA和 Mysql 等
- 单击页面底部的“生成项目”按钮。
- 将项目导入Eclipse或IDea,Idea内部已经集成了这个导航功能。
屏幕截图显示了导入的maven项目的项目结构。
- DemoApplication.java - Spring Boot Launcher。初始化Spring Boot自动配置和Spring应用程序上下文。
- application.properties - 应用程序配置文件。
- DemoApplicationTests.java - 用于单元测试的简单启动器。
- pom.xml - 包含Spring Boot Starter Web的依赖项。使用Spring Boot Starter Parent作为父pom。
让我们看一下生成的每个文件
/pom.xml
在pom.xml中配置的三个重要事项。
- Spring Boot Parent Pom - 您可以在这里阅读有关Spring Boot Starter Parent的更多信息 。
- Spring Boot Starter Web - 您可以在此处阅读有关Spring Boot Starter Web的更多信息
- Spring Boot Starter插件
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
代码:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@SpringBootApplication - 初始化Spring Boot自动配置和Spring应用程序上下文。详细见这里SpringApplication.run - 启动Spring Boot应用程序的静态方法。
当您将DemoApplication.java作为 Java 应用程序运行时,将生成以下日志:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.8.RELEASE)
2018-09-19 14:32:29.277 INFO 17776 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on banqjdon with PID 17776 (D:\temp\demo\target\classes started by banq in D:\temp\demo)
2018-09-19 14:32:29.279 INFO 17776 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2018-09-19 14:32:29.331 INFO 17776 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2357d90a: startup date [Wed Sep 19 14:32:29 CST 2018]; root of context hierarchy
恭喜,Web应用已经在http://localhost:8080可启动了。当然如果需要可访问,还需要配置REST端口。
Spring Boot
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 测试应用启动性能
- Androd 应用启动过程的源码分析
- Android源码分析--应用程序启动
- Android 应用启动性能:延迟初始化
- 笔记-iOS应用程序的启动过程
- 让我们让SpringBoot应用程序更快启动
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Ext JS源码分析与开发实例宝典
彭仁夔 / 电子工业出版社 / 2010-1 / 78.00元
《Ext JS源码分析与开发实例宝典》从Ext JS实现的基本功能开始讲解,从两个方面对Ext JS进行整体上的概述,让读者从宏观上去把握ExtJS框架。接下来讲解Ext JS核心基础知识,包括事件机制、模板模型、数据模型以及对类、函数、字符串、日期、数组及定时任务这6个类进行扩展。然后讲解Ext JS基于元素的开发,包括动画特效和拖曳实现等。最后深入讲解组件的开发,对布局、模型及4大组件一一进行......一起来看看 《Ext JS源码分析与开发实例宝典》 这本书的介绍吧!
CSS 压缩/解压工具
在线压缩/解压 CSS 代码
在线进制转换器
各进制数互转换器