Spring Boot 2.0.2 教程 - Hello World 之 intellij idea 创建web项目 - 02
非原创 java_world 发表于:2018-07-04 10:23:15
  阅读 :121   收藏   编辑

上一篇 Spring Boot 2.0.2 教程 - Hello World - 01 

1.开始啦

g_1

2.在左侧菜单中选择 Spring Initializr ,右侧 Project SDK使用1.8,如果没有的话点击右侧New...按钮

g_2

3.填写自己的包名,项目名称等,这里我全部保持默认

g_3

4.在这个选择依赖的界面窗口,选择Web里的Web即可

g_4

5.接下来就等待项目初始化,下载相关依赖了

  • 如果要更新maven项目配置,可在File->Settings中找到maven来更换你的仓库地址

  • 如果在依赖下载过程中出现错误,可以点击项目右键->Maven->Reimport

6.新建测试controller,目录及内容参考如下

g_6

HelloController.java

package com.example.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by Administrator on 2018/7/4.
 */
@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String print(){
        return "Hi Spring Boot2.0.2 ";
    }
}


7.启动,在DemoApplication.java中右键Run DemoApplication

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

2018-07-04 10:01:03.035  INFO 7888 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication on WIN-N71UG691JA6 with PID 7888 (G:\work\idea_tmp\demo\target\classes started by Administrator in G:\work\idea_tmp\demo)
2018-07-04 10:01:03.038  INFO 7888 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2018-07-04 10:01:03.145  INFO 7888 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@c8e4bb0: startup date [Wed Jul 04 10:01:03 CST 2018]; root of context hierarchy
2018-07-04 10:01:05.151  INFO 7888 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-07-04 10:01:05.174  INFO 7888 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-07-04 10:01:05.174  INFO 7888 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-07-04 10:01:05.178  INFO 7888 --- [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 Files\Java\jdk1.8.0_73\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.8.0_73\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;E:\install\pl\PLSQL\instantclient_11_2;E:\install\apache-maven-3.3.3\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;E:\install\Git\cmd;E:\install\svn-c\bin;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files\MySQL\MySQL Server 5.7\bin;E:\install\apache-maven-3.1.1\bin;E:\install\putty\;E:\install\nodejs\;E:\install\ue\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Users\Administrator\AppData\Roaming\npm;.]
2018-07-04 10:01:05.295  INFO 7888 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-07-04 10:01:05.295  INFO 7888 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2157 ms
2018-07-04 10:01:05.429  INFO 7888 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-07-04 10:01:05.432  INFO 7888 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-07-04 10:01:05.433  INFO 7888 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-07-04 10:01:05.433  INFO 7888 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-07-04 10:01:05.433  INFO 7888 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-07-04 10:01:05.526  INFO 7888 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-04 10:01:05.719  INFO 7888 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@c8e4bb0: startup date [Wed Jul 04 10:01:03 CST 2018]; root of context hierarchy
2018-07-04 10:01:05.769  INFO 7888 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello]}" onto public java.lang.String com.example.demo.controller.HelloController.print()
2018-07-04 10:01:05.775  INFO 7888 --- [           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-07-04 10:01:05.776  INFO 7888 --- [           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-07-04 10:01:05.798  INFO 7888 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-04 10:01:05.798  INFO 7888 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-04 10:01:05.939  INFO 7888 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-07-04 10:01:05.978  INFO 7888 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-07-04 10:01:05.982  INFO 7888 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 3.406 seconds (JVM running for 4.038)
2018-07-04 10:01:18.037  INFO 7888 --- [nio-8080-exec-1] o.apache.tomcat.util.http.parser.Cookie  : A cookie header was received [1519279204,1519362948,1519975475; _ga=GA1.1.680000235.1520239915] that contained an invalid cookie. That cookie will be ignored.Note: further occurrences of this error will be logged at DEBUG level.
2018-07-04 10:01:18.044  INFO 7888 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-07-04 10:01:18.044  INFO 7888 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2018-07-04 10:01:18.061  INFO 7888 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 16 ms

8.访问

http://localhost:8080/hello

g_7