美文网首页
springboot2.2.6.RELEASE chapter1

springboot2.2.6.RELEASE chapter1

作者: 淼哥1986 | 来源:发表于2020-04-03 11:22 被阅读0次

The SpringApplication class provides a convenient way to bootstrap a Spring application that is started from a main() method. In many situations, you can delegate to the static SpringApplication.run method, as shown in the following example:

public static void main(String[] args) {
    SpringApplication.run(MySpringConfiguration.class, args);
}

example:

1. pom文件

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
        <relativePath/>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>
    <artifactId>chapter1</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

2. 编写application.java

package com.github.examples;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

    @ResponseBody
    @RequestMapping("/hello")
    public String hello() {
        return "Hello World";
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

3.运行

Connected to the target VM, address: '127.0.0.1:52067', transport: 'socket'

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.5.RELEASE)

2020-04-03 11:17:59.051  INFO 1600 --- [           main] com.github.examples.DemoApplication      : Starting DemoApplication on DESKTOP-GLVVPCF with PID 1600 (D:\03github\springboot2-learning\chapter2\target\classes started by limiao in D:\03github\springboot2-learning)
2020-04-03 11:17:59.066  INFO 1600 --- [           main] com.github.examples.DemoApplication      : No active profile set, falling back to default profiles: default
2020-04-03 11:18:02.066  INFO 1600 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-04-03 11:18:02.097  INFO 1600 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-04-03 11:18:02.097  INFO 1600 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-04-03 11:18:02.879  INFO 1600 --- [           main] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2020-04-03 11:18:02.879  INFO 1600 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-04-03 11:18:02.879  INFO 1600 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3531 ms
2020-04-03 11:18:02.957  INFO 1600 --- [           main] o.s.boot.web.servlet.RegistrationBean    : Servlet dispatcherServlet was not registered (possibly already registered?)
2020-04-03 11:18:07.540  INFO 1600 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-04-03 11:18:08.050  INFO 1600 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
2020-04-03 11:18:08.810  INFO 1600 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-04-03 11:18:08.820  INFO 1600 --- [           main] com.github.examples.DemoApplication      : Started DemoApplication in 11.061 seconds (JVM running for 17.483)

4.访问测试

浏览器输入 http://localhost:8080/hello

image.png

结束

相关文章

网友评论

      本文标题:springboot2.2.6.RELEASE chapter1

      本文链接:https://www.haomeiwen.com/subject/ewxhphtx.html