zoukankan      html  css  js  c++  java
  • Spring Boot系列之-helloword入门

    一. What: Spring Boot是什么?
    以1.4.3.RELEASE为例,官方介绍为:http://docs.spring.io/spring-boot/docs/1.4.3.RELEASE/reference/html/getting-started-introducing-spring-boot.html 。

    简单来说,使用Spring Boot能够非常方便,快速地开发一个基于Spring框架,可独立运行的应用程序。

    具体来说,Spring Boot集成了一些在项目中常用的组件,比如:嵌入式服务器,安全等。而且在使用Spring Boot开发应用程序时,完全不需要XML配置。

    二. Why: 为什么Spring Boot能如此易用?
    //TODO: 随后再详细介绍

    三. How: 如何建立一个简单的Spring Boot应用程序?

    环境要求:
    1. JDK: Although you can use Spring Boot with Java 6 or 7, we generally recommend Java 8 if at all possible. 
    2. Maven: Spring Boot is compatible with Apache Maven 3.2 or above.

    示例项目:

    1. 新建一个maven项目,并在pom.xml中添加如下依赖配置:

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     4 <modelVersion>4.0.0</modelVersion>
     5 
     6 <groupId>org.chench</groupId>
     7 <artifactId>springboot-hellworld</artifactId>
     8 <version>1.0.0</version>
     9 <packaging>jar</packaging>
    10 
    11 <name>springboot-hellworld</name>
    12 <url>http://maven.apache.org</url>
    13 
    14 <!-- 使用spring boot框架:声明spring boot为父依赖 -->
    15 <parent>
    16 <groupId>org.springframework.boot</groupId>
    17 <artifactId>spring-boot-starter-parent</artifactId>
    18 <version>1.4.3.RELEASE</version>
    19 </parent>
    20 
    21 <properties>
    22 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    23 </properties>
    24 
    25 <dependencies>
    26 <!-- 开发web应用 -->
    27 <dependency>
    28 <groupId>org.springframework.boot</groupId>
    29 <artifactId>spring-boot-starter-web</artifactId>
    30 </dependency>
    31 
    32 <dependency>
    33 <groupId>junit</groupId>
    34 <artifactId>junit</artifactId>
    35 <scope>test</scope>
    36 </dependency>
    37 </dependencies>
    38 
    39 <build>
    40 <plugins>
    41 <!-- 打包插件: 可将项目打包为独立执行的jar文件 -->
    42 <plugin>
    43 <groupId>org.springframework.boot</groupId>
    44 <artifactId>spring-boot-maven-plugin</artifactId>
    45 </plugin>
    46 </plugins>
    47 </build>
    48 
    49 </project>
    View Code

    2. 新建HelloWordApplication:

     1 @RestController
     2 @EnableAutoConfiguration
     3 public class HelloWordApplication {
     4 
     5 @RequestMapping("/")
     6 public String helloworld() {
     7 return "hello,world";
     8 }
     9 
    10 public static void main(String[] args) {
    11 SpringApplication.run(HelloWordApplication.class, args);
    12 }
    13 }
    View Code

    3.运行HelloWordApplication:
    如果是在eclipse等开发环境中,直接运行: "Run As" -> "Java Application" 。
    或者,直接将项目打包为可独立执行的jar文件: mvn clean package,将生成文件: springboot-hellworld-version.jar 。 执行如下命令启动项目: java -jar springboot-hellworld-version.jar


    启动之后,在浏览器地址栏输入: http://localhost:8080/

    完毕!

  • 相关阅读:
    反射 Reflection
    后台输出的数据进行字符判断,小数点后边是0不显示,不是0显示
    判断input内的字符是不是数字或字母
    手机端底部按钮隐藏与显示
    CSS改变checkbox样式
    js小数取整 小数保留两位
    如何判断打开页面时使用的设备?
    H5 拖放实例
    根据手机系统引入不同的css文件
    HTML 5 video 视频标签全属性详解(转)
  • 原文地址:https://www.cnblogs.com/nuccch/p/6219993.html
Copyright © 2011-2022 走看看