第2章 构建springboot工程 2-2 使用Spring官方STS搭建SpringBoot工程

项目名demo,SpringBoot的版本2.0.6

 

 

 

删了/demo/mvnw和/demo/mvnw.cmd。static文件夹包含静态文件,比如CSS、JS。templates文件夹是放模板的,SpringBoot官方推荐的模板是使用thymeleaf,SSM使用freemarker比较多。国产的Beetl也可以放到templates文件夹里面。

删掉/demo/src/test的内容,pom.xml删掉这一段

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

运行/demo/src/main/java/com/example/demo/DemoApplication.java

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

2018-10-27 05:21:21.096  INFO 19680 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication on DESKTOP-S07DGSI with PID 19680 (G:eclipse-workspacedemo	argetclasses started by ZHONGZHENHUA in G:eclipse-workspacedemo)
2018-10-27 05:21:21.104  INFO 19680 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2018-10-27 05:21:21.308  INFO 19680 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7d68ef40: startup date [Sat Oct 27 05:21:21 CST 2018]; root of context hierarchy
2018-10-27 05:21:25.219  INFO 19680 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-10-27 05:21:25.315  INFO 19680 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-10-27 05:21:25.316  INFO 19680 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-10-27 05:21:25.341  INFO 19680 --- [ost-startStop-1] 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 FilesJavajre1.8.0_144in;C:WINDOWSSunJavain;C:WINDOWSsystem32;C:WINDOWS;C:/Program Files/Java/jre1.8.0_144/bin/server;C:/Program Files/Java/jre1.8.0_144/bin;C:/Program Files/Java/jre1.8.0_144/lib/amd64;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0in;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0libnvvp;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.0in;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.0libnvvp;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.2in;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.2libnvvp;C:ProgramDataOracleJavajavapath;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;D:BaiduNetdiskDownloadadt-bundle-windows-x86_64_20140101adt-bundle-windows-x86_64_20140101sdkplatform-tools;D:BaiduNetdiskDownloadadt-bundle-windows-x86_64_20140101adt-bundle-windows-x86_64_20140101sdkplatform-tools;C:Program FilesJavajdk1.8.0_144in;C:Program FilesJavajdk1.8.0_144jrein;I:数据库数据库3mysql-5.7.21-winx64mysql-5.7.21-winx64in;H:NDKandroid-ndk-r9d-windows-x86_64android-ndk-r9d;D:UsersHONGZHENHUAAnaconda3;C:Program FilesGitcmd;C:Program Files
odejs;C:UsersHONGZHENHUAServermavenapache-maven-3.5.2in;C:Program FilesTortoiseGitin;C:WINDOWSSystem32OpenSSH;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program FilesNVIDIA GPU Computing Toolkitcudnnin;D:UsersHONGZHENHUAAnaconda3Scripts;C:Program FilesNVIDIA GPU Computing Toolkitcudnnin;C:ProgramDataNVIDIA GPU Computing Toolkitv9.0;C:UsersHONGZHENHUA.dnxin;C:Program FilesMicrosoft DNXDnvm;C:Program FilesMicrosoft SQL Server130ToolsBinn;C:ProgramDataNVIDIA GPU Computing Toolkitv8.0;C:UsersHONGZHENHUAAppDataLocalMicrosoftWindowsApps;C:UsersHONGZHENHUAAppDataRoaming
pm;D:WindWind.NET.ClientWindNETin;G:eclipse-jee-2018-09-win32-x86_64eclipse;;.]
2018-10-27 05:21:25.599  INFO 19680 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-10-27 05:21:25.599  INFO 19680 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4296 ms
2018-10-27 05:21:25.830  INFO 19680 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-10-27 05:21:25.840  INFO 19680 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-10-27 05:21:25.841  INFO 19680 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-10-27 05:21:25.841  INFO 19680 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-10-27 05:21:25.841  INFO 19680 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-10-27 05:21:26.137  INFO 19680 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-27 05:21:26.457  INFO 19680 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7d68ef40: startup date [Sat Oct 27 05:21:21 CST 2018]; root of context hierarchy
2018-10-27 05:21:26.786  INFO 19680 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-10-27 05:21:26.790  INFO 19680 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-10-27 05:21:26.889  INFO 19680 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-27 05:21:26.892  INFO 19680 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-27 05:21:27.412  INFO 19680 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-10-27 05:21:27.573  INFO 19680 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-10-27 05:21:27.582  INFO 19680 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 7.287 seconds (JVM running for 8.204)

因为没有配置controler,所以它运行了一遍就关掉了。

/demo/pom.xml

<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</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.6.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-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
原文地址:https://www.cnblogs.com/ZHONGZHENHUA/p/9859908.html