SpringBoot入门-1(Hello Word Boot)
Posted 码路编程
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot入门-1(Hello Word Boot)相关的知识,希望对你有一定的参考价值。
Spring Boot 是由Pivotal团队提供的全新框架,其设计目的是用来简化新的Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。
以下是SpringBoot的快速搭建。
1、创建一个Maven项目,添加一个parent,代码如下
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.4.RELEASE</version> </parent>
2、添加一个依赖
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
3、配置java版本,若不填,默认1.6
<build> <!-- 配置java版本 不配置的话默认父类配置的是1.6--> <pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </pluginManagement> </build>
4、新建一个java文件
package com.test; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @RestController 相当于@Controller和@RequestBody * */ @RestController @EnableAutoConfiguration public class HelloController { @RequestMapping("/hello") public String hello(){ return "Hello Word SpringBoot"; } public static void main(String[] args) { SpringApplication.run(HelloController.class, args); } }
最后run运行
. ____ _ __ _ _ /\\\\ / ___\'_ __ _ _(_)_ __ __ _ \\ \\ \\ \\ ( ( )\\___ | \'_ | \'_| | \'_ \\/ _` | \\ \\ \\ \\ \\\\/ ___)| |_)| | | | | || (_| | ) ) ) ) \' |____| .__|_| |_|_| |_\\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.3.4.RELEASE) 2017-08-12 13:51:00.098 INFO 2124 --- [ main] com.test.HelloController : Starting HelloController on DESKTOP-M8DR5S3 with PID 2124 (F:\\MyEclipse\\mywork\\spinrBoot-hello\\target\\classes started by 592302116 in F:\\MyEclipse\\mywork\\spinrBoot-hello) 2017-08-12 13:51:00.113 INFO 2124 --- [ main] com.test.HelloController : No active profile set, falling back to default profiles: default 2017-08-12 13:51:00.160 INFO 2124 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5b0de4ee: startup date [Sat Aug 12 13:51:00 CST 2017]; root of context hierarchy 2017-08-12 13:51:01.770 INFO 2124 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http) 2017-08-12 13:51:01.815 INFO 2124 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2017-08-12 13:51:01.815 INFO 2124 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.33 2017-08-12 13:51:01.955 INFO 2124 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2017-08-12 13:51:01.955 INFO 2124 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1795 ms 2017-08-12 13:51:02.299 INFO 2124 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: \'dispatcherServlet\' to [/] 2017-08-12 13:51:02.315 INFO 2124 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: \'characterEncodingFilter\' to: [/*] 2017-08-12 13:51:02.315 INFO 2124 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: \'hiddenHttpMethodFilter\' to: [/*] 2017-08-12 13:51:02.315 INFO 2124 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: \'httpPutFormContentFilter\' to: [/*] 2017-08-12 13:51:02.315 INFO 2124 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: \'requestContextFilter\' to: [/*] 2017-08-12 13:51:02.565 INFO 2124 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5b0de4ee: startup date [Sat Aug 12 13:51:00 CST 2017]; root of context hierarchy 2017-08-12 13:51:02.630 INFO 2124 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello]}" onto public java.lang.String com.test.HelloController.hello() 2017-08-12 13:51:02.630 INFO 2124 --- [ 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) 2017-08-12 13:51:02.630 INFO 2124 --- [ 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) 2017-08-12 13:51:02.708 INFO 2124 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-08-12 13:51:02.708 INFO 2124 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-08-12 13:51:02.802 INFO 2124 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-08-12 13:51:02.958 INFO 2124 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2017-08-12 13:51:03.083 INFO 2124 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 2017-08-12 13:51:03.083 INFO 2124 --- [ main] com.test.HelloController : Started HelloController in 3.329 seconds (JVM running for 3.61) 2017-08-12 13:51:32.885 INFO 2124 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet \'dispatcherServlet\' 2017-08-12 13:51:32.885 INFO 2124 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet \'dispatcherServlet\': initialization started 2017-08-12 13:51:32.900 INFO 2124 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet \'dispatcherServlet\': initialization completed in 15 ms
在url输入http://127.0.0.1:8080/hello
页面将展示出来
公众号
欢迎关注我的公众号“码上开发”,每天分享最新技术资讯、最优原创文章。关注获取最新资源
版权声明:本文为不会代码的小白原创文章,未经允许不得转载。
以上是关于SpringBoot入门-1(Hello Word Boot)的主要内容,如果未能解决你的问题,请参考以下文章
windows环境 springboot+docker开发环境搭建与hello word
windows环境 springboot+docker开发环境搭建与hello word