暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

spring-boot 环境搭建

菜涛学Java 2019-02-21
211

搭建spring-boot项目环境

spring-boot-study github源码 : https://github.com/1769974308/spring-boot-study

spring-boot 博客 : https://1769974308.github.io/blog/frame/springboot/build-springboot-project.html

一、环境

  • jdk1.8

  • maven

  • intellij idea

二、创建项目

1、file->new->project

2、选择spring initializr

spring initializr是官方的构建插件,也可以选择maven

3、填写项目基本信息

group:组织id,一般分为多个段 com.taotaojava artifact:唯一标识符,项目名称

4、选择包

spring initializr提供很多选项,当前只选择web-web

三、目录结构

  1. - src

  2.    -main

  3.        -java

  4.            -package

  5.                #主函数,启动类,运行它如果运行了 Tomcat、Jetty、Undertow 等容器

  6.                -SpringbootApplication

  7.        -resouces

  8.            #存放静态资源 js/css/images 等

  9.            - statics

  10.            #存放 html 模板文件

  11.            - templates

  12.            #主要的配置文件,SpringBoot启动时候会自动加载application.yml/application.properties

  13.            - application.yml

  14.    #测试文件存放目录

  15.    -test

  16. # pom.xml 文件是Maven构建的基础,里面包含了我们所依赖JAR和Plugin的信息

  17. - pom

四、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.    <groupId>com.taotaojava</groupId>

  6.    <artifactId>spring-boot-study</artifactId>

  7.    <version>0.0.1-SNAPSHOT</version>

  8.    <name>spring-boot-study</name>

  9.    <description>spring-boot-study project for Spring Boot</description>



  10.    <parent>

  11.        <groupId>org.springframework.boot</groupId>

  12.        <artifactId>spring-boot-starter-parent</artifactId>

  13.        <version>2.1.3.RELEASE</version>

  14.        <relativePath/> <!-- lookup parent from repository -->

  15.    </parent>


  16.    <properties>

  17.        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

  18.        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

  19.        <java.version>1.8</java.version>

  20.        <skipTests>true</skipTests>

  21.    </properties>


  22.    <dependencies>

  23.        <!-- 默认内嵌Tomcat 容器-->

  24.        <dependency>

  25.            <groupId>org.springframework.boot</groupId>

  26.            <artifactId>spring-boot-starter-web</artifactId>

  27.        </dependency>


  28.        <dependency>

  29.            <groupId>org.springframework.boot</groupId>

  30.            <artifactId>spring-boot-starter-test</artifactId>

  31.            <scope>test</scope>

  32.        </dependency>

  33.    </dependencies>


  34.    <build>

  35.        <plugins>

  36.            <!-- 编译插件 -->

  37.            <plugin>

  38.                <groupId>org.springframework.boot</groupId>

  39.                <artifactId>spring-boot-maven-plugin</artifactId>

  40.            </plugin>

  41.        </plugins>

  42.    </build>


  43. </project>

五、运行

主函数->run debug

  1.  .   ____          _            __ _ _

  2. /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \

  3. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \

  4. \\/  ___)| |_)| | | | | || (_| |  ) ) ) )

  5.  '  |____| .__|_| |_|_| |_\__, | / / /

  6. =========|_|==============|___/=/_/_/_/

  7. :: Spring Boot ::        (v2.1.3.RELEASE)


  8. 2019-02-19 23:41:01.435  INFO 9884 --- [           main] c.taotaojava.SpringBootStudyApplication  : Starting SpringBootStudyApplication on 56085K6EEVYTC6Y with PID 9884 (D:\giteeWorkspace\springbootstudy\target\classes started by Administrator in D:\giteeWorkspace\springbootstudy)

  9. 2019-02-19 23:41:01.444  INFO 9884 --- [           main] c.taotaojava.SpringBootStudyApplication  : No active profile set, falling back to default profiles: default

  10. 2019-02-19 23:41:04.550  INFO 9884 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)

  11. 2019-02-19 23:41:04.607  INFO 9884 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]

  12. 2019-02-19 23:41:04.608  INFO 9884 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.16]

  13. 2019-02-19 23:41:04.626  INFO 9884 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_201\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;d:\oracle\product\10.2.0\client_1\bin;D:\oracle\product\10.2.0\db_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\Java\jdk1.7.0_17\bin;C:\Program Files\Java\jdk1.7.0_17\jre\bin;D:\java\mysql-5.6.24-winx64\bin;D:\java\TortoiseGit\install\bin;D:\java\apache-maven-3.3.9\bin;D:\java\SVNSerivec\Server\bin;D:\java\Git\Git\cmd;.]

  14. 2019-02-19 23:41:04.817  INFO 9884 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext

  15. 2019-02-19 23:41:04.817  INFO 9884 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2925 ms

  16. 2019-02-19 23:41:05.303  INFO 9884 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'

  17. 2019-02-19 23:41:05.754  INFO 9884 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''

  18. 2019-02-19 23:41:05.759  INFO 9884 --- [           main] c.taotaojava.SpringBootStudyApplication  : Started Spr


文章转载自菜涛学Java,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论