spring-boot环境搭建

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring-boot环境搭建相关的知识,希望对你有一定的参考价值。

1、下载:spring-tool-suite-3.9.2.RELEASE-e4.7.2-win32-x86_64
http://spring.io/tools/sts/all
解压后点击
技术分享图片

配置Maven
技术分享图片

新建项目:
技术分享图片
输入项目名称:
技术分享图片

输入web
技术分享图片
显示成功:
技术分享图片

新建类:
技术分享图片

类里编写:

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Hello {

    @RequestMapping(value="/helloworld")
    public String helloWorld() {
        return "hello world";
    }

}

启动,并且访问:
技术分享图片

 .   ____          _            __ _ _
 /\\ / ___‘_ __ _ _(_)_ __  __ _ \ \ \ ( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  ‘  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.9.RELEASE)

2018-01-25 11:07:54.340  INFO 2696 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication on liwen-pc with PID 2696 (D:\TOOL\sptingspcae\demo\target\classes started by lw in D:\TOOL\sptingspcae\demo)
2018-01-25 11:07:54.344  INFO 2696 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2018-01-25 11:07:54.406  INFO 2696 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]6366ebe0: startup date [Thu Jan 25 11:07:54 CST 2018]; root of context hierarchy
2018-01-25 11:07:55.778  INFO 2696 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-01-25 11:07:55.790  INFO 2696 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-01-25 11:07:55.791  INFO 2696 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.23
2018-01-25 11:07:55.872  INFO 2696 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-01-25 11:07:55.872  INFO 2696 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1470 ms
2018-01-25 11:07:56.038  INFO 2696 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: ‘dispatcherServlet‘ to [/]
2018-01-25 11:07:56.043  INFO 2696 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘characterEncodingFilter‘ to: [/*]
2018-01-25 11:07:56.044  INFO 2696 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘hiddenHttpMethodFilter‘ to: [/*]
2018-01-25 11:07:56.044  INFO 2696 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘httpPutFormContentFilter‘ to: [/*]
2018-01-25 11:07:56.044  INFO 2696 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘requestContextFilter‘ to: [/*]
2018-01-25 11:07:56.429  INFO 2696 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot[email protected]6366ebe0: startup date [Thu Jan 25 11:07:54 CST 2018]; root of context hierarchy
2018-01-25 11:07:56.507  INFO 2696 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user]}" onto public com.example.demo.bean.User com.example.demo.web.HelloWorldController.getUser()
2018-01-25 11:07:56.508  INFO 2696 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/helloworld]}" onto public java.lang.String com.example.demo.web.HelloWorldController.helloWorld()
2018-01-25 11:07:56.513  INFO 2696 --- [           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.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-01-25 11:07:56.513  INFO 2696 --- [           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.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-01-25 11:07:56.556  INFO 2696 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-25 11:07:56.557  INFO 2696 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-25 11:07:56.620  INFO 2696 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-25 11:07:56.801  INFO 2696 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-01-25 11:07:56.891  INFO 2696 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-01-25 11:07:56.896  INFO 2696 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 2.828 seconds (JVM running for 3.859)
2018-01-25 11:10:44.860  INFO 2696 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet ‘dispatcherServlet‘
2018-01-25 11:10:44.860  INFO 2696 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet ‘dispatcherServlet‘: initialization started
2018-01-25 11:10:44.878  INFO 2696 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet ‘dispatcherServlet‘: initialization completed in 17 ms

显示成功:
技术分享图片

以上是关于spring-boot环境搭建的主要内容,如果未能解决你的问题,请参考以下文章

spring-boot入门之一——环境搭建

解决spring-boot启动中碰到的问题:Cannot determine embedded database driver class for database type NONE(转)(代码片段

spring练习,在Eclipse搭建的Spring开发环境中,使用set注入方式,实现对象的依赖关系,通过ClassPathXmlApplicationContext实体类获取Bean对象(代码片段

Spring-Boot - 初步搭建

node 环境下简单web服务器搭建代码

SpringBoot 环境搭建