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";
}
}
启动,并且访问:
. ____ _ __ _ _
/\\ / ___‘_ __ _ _(_)_ __ __ _ \ \ \ ( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) )
‘ |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
[32m :: Spring Boot :: [39m [2m (v1.5.9.RELEASE)[0;39m
[2m2018-01-25 11:07:54.340[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36mcom.example.demo.DemoApplication [0;39m [2m:[0;39m Starting DemoApplication on liwen-pc with PID 2696 (D:\TOOL\sptingspcae\demo\target\classes started by lw in D:\TOOL\sptingspcae\demo)
[2m2018-01-25 11:07:54.344[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36mcom.example.demo.DemoApplication [0;39m [2m:[0;39m No active profile set, falling back to default profiles: default
[2m2018-01-25 11:07:54.406[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36mationConfigEmbeddedWebApplicationContext[0;39m [2m:[0;39m Refreshing org.springframework.boot[email protected]6366ebe0: startup date [Thu Jan 25 11:07:54 CST 2018]; root of context hierarchy
[2m2018-01-25 11:07:55.778[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.b.c.e.t.TomcatEmbeddedServletContainer[0;39m [2m:[0;39m Tomcat initialized with port(s): 8080 (http)
[2m2018-01-25 11:07:55.790[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.StandardService [0;39m [2m:[0;39m Starting service [Tomcat]
[2m2018-01-25 11:07:55.791[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36morg.apache.catalina.core.StandardEngine [0;39m [2m:[0;39m Starting Servlet Engine: Apache Tomcat/8.5.23
[2m2018-01-25 11:07:55.872[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext
[2m2018-01-25 11:07:55.872[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.web.context.ContextLoader [0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 1470 ms
[2m2018-01-25 11:07:56.038[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.b.w.servlet.ServletRegistrationBean [0;39m [2m:[0;39m Mapping servlet: ‘dispatcherServlet‘ to [/]
[2m2018-01-25 11:07:56.043[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean [0;39m [2m:[0;39m Mapping filter: ‘characterEncodingFilter‘ to: [/*]
[2m2018-01-25 11:07:56.044[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean [0;39m [2m:[0;39m Mapping filter: ‘hiddenHttpMethodFilter‘ to: [/*]
[2m2018-01-25 11:07:56.044[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean [0;39m [2m:[0;39m Mapping filter: ‘httpPutFormContentFilter‘ to: [/*]
[2m2018-01-25 11:07:56.044[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean [0;39m [2m:[0;39m Mapping filter: ‘requestContextFilter‘ to: [/*]
[2m2018-01-25 11:07:56.429[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerAdapter[0;39m [2m:[0;39m Looking for @ControllerAdvice: org.springframework.boot[email protected]6366ebe0: startup date [Thu Jan 25 11:07:54 CST 2018]; root of context hierarchy
[2m2018-01-25 11:07:56.507[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped "{[/user]}" onto public com.example.demo.bean.User com.example.demo.web.HelloWorldController.getUser()
[2m2018-01-25 11:07:56.508[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped "{[/helloworld]}" onto public java.lang.String com.example.demo.web.HelloWorldController.helloWorld()
[2m2018-01-25 11:07:56.513[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m 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)
[2m2018-01-25 11:07:56.513[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m 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)
[2m2018-01-25 11:07:56.556[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
[2m2018-01-25 11:07:56.557[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
[2m2018-01-25 11:07:56.620[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
[2m2018-01-25 11:07:56.801[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.j.e.a.AnnotationMBeanExporter [0;39m [2m:[0;39m Registering beans for JMX exposure on startup
[2m2018-01-25 11:07:56.891[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.b.c.e.t.TomcatEmbeddedServletContainer[0;39m [2m:[0;39m Tomcat started on port(s): 8080 (http)
[2m2018-01-25 11:07:56.896[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[ main][0;39m [36mcom.example.demo.DemoApplication [0;39m [2m:[0;39m Started DemoApplication in 2.828 seconds (JVM running for 3.859)
[2m2018-01-25 11:10:44.860[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring FrameworkServlet ‘dispatcherServlet‘
[2m2018-01-25 11:10:44.860[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m FrameworkServlet ‘dispatcherServlet‘: initialization started
[2m2018-01-25 11:10:44.878[0;39m [32m INFO[0;39m [35m2696[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m FrameworkServlet ‘dispatcherServlet‘: initialization completed in 17 ms
显示成功:
以上是关于spring-boot环境搭建的主要内容,如果未能解决你的问题,请参考以下文章
解决spring-boot启动中碰到的问题:Cannot determine embedded database driver class for database type NONE(转)(代码片段
spring练习,在Eclipse搭建的Spring开发环境中,使用set注入方式,实现对象的依赖关系,通过ClassPathXmlApplicationContext实体类获取Bean对象(代码片段