博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
从零开始学springboot笔记(一)-Spring boot之Hello Word
阅读量:5236 次
发布时间:2019-06-14

本文共 6266 字,大约阅读时间需要 20 分钟。

工具:Eclipse、jdk1.8、maven;一:先建一个maven的项目

然后再pom文件中添加相关依赖和配置,具体如下:  
org.springframework.boot
spring-boot-starter-parent
1.4.1.RELEASE
UTF-8
1.8
org.springframework.boot
spring-boot-starter-web
注意添加依赖后,记得update;
然后创建HelloController,code如下:import java.util.Date;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HelloController {    @RequestMapping("/hello")    public String hello(){                return "hello";    }}

然后编码springboot启动类App.java

@SpringBootApplicationpublic class App// extends WebMvcConfigurerAdapter {    public static void main( String[] args )    {        System.out.println( "--------------开始启动---------------!" );        SpringApplication.run(App.class, args);        System.out.println( "--------------启动成功---------------!" );    }}

打开app.java,右键run as java application启动springboot应用;

--------------开始启动---------------!  .   ____          _            __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/  ___)| |_)| | | | | || (_| |  ) ) ) )  '  |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::        (v1.4.1.RELEASE)2019-05-27 15:27:52.942  INFO 2020 --- [           main] com.feiyun.springboot_hello.App          : Starting App on TEST-PC with PID 2020 (E:\Eclise\MyWorkPlace\springboot-hello\target\classes started by Administrator in E:\Eclise\MyWorkPlace\springboot-hello)2019-05-27 15:27:52.944  INFO 2020 --- [           main] com.feiyun.springboot_hello.App          : No active profile set, falling back to default profiles: default2019-05-27 15:27:52.985  INFO 2020 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4b0b0854: startup date [Mon May 27 15:27:52 CST 2019]; root of context hierarchy2019-05-27 15:27:54.084  INFO 2020 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)2019-05-27 15:27:54.097  INFO 2020 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat2019-05-27 15:27:54.099  INFO 2020 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.52019-05-27 15:27:54.180  INFO 2020 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext2019-05-27 15:27:54.180  INFO 2020 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1198 ms2019-05-27 15:27:54.327  INFO 2020 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]2019-05-27 15:27:54.331  INFO 2020 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]2019-05-27 15:27:54.331  INFO 2020 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]2019-05-27 15:27:54.331  INFO 2020 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]2019-05-27 15:27:54.332  INFO 2020 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]2019-05-27 15:27:54.592  INFO 2020 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4b0b0854: startup date [Mon May 27 15:27:52 CST 2019]; root of context hierarchy2019-05-27 15:27:54.647  INFO 2020 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello]}" onto public java.lang.String com.feiyun.springboot_hello.HelloController.hello()2019-05-27 15:27:54.648  INFO 2020 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/getDemo]}" onto public com.feiyun.springboot_hello.Demo com.feiyun.springboot_hello.HelloController.getDemo()2019-05-27 15:27:54.652  INFO 2020 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity
> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)2019-05-27 15:27:54.652 INFO 2020 --- [ 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)2019-05-27 15:27:54.674 INFO 2020 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]2019-05-27 15:27:54.674 INFO 2020 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]2019-05-27 15:27:54.706 INFO 2020 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]2019-05-27 15:27:54.825 INFO 2020 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup2019-05-27 15:27:54.870 INFO 2020 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)2019-05-27 15:27:54.873 INFO 2020 --- [ main] com.feiyun.springboot_hello.App : Started App in 2.258 seconds (JVM running for 2.533)--------------启动成功---------------!

运行成功后,打开浏览器访问hello方法,注意默认端口是8080;

 

 end;

 

 

hello

转载于:https://www.cnblogs.com/YLQBL/p/10931105.html

你可能感兴趣的文章
svn“Previous operation has not finished; run 'cleanup' if it was interrupted“报错的解决方法...
查看>>
项目经理面试中可能遇到的问题(持续更新)
查看>>
【转】总结前端面试过程中最容易出现的问题
查看>>
Java- 简单了解线程 生产者与消费者问题(三)
查看>>
centos rancher 通过本机 docker images 新增container
查看>>
【原】PNG的使用技巧
查看>>
android studio 使用SVN 锁定文件,防止别人修改(基于Android studio 1.4 )
查看>>
4412 uboot启动分析
查看>>
熟用TableView
查看>>
IO模型《六》IO模型比较分析
查看>>
Android 博客园客户端 (七)登录功能
查看>>
PHP动态页面 生产静态页 方法二
查看>>
Java大数——a^b + b^a
查看>>
zcmu 1041
查看>>
POJ-2533 Longest Ordered Subsequence ( DP )
查看>>
poj 3164 最小树形图(朱刘算法)
查看>>
百度贴吧图片抓取工具
查看>>
服务器内存泄露 , 重启后恢复问题解决方案
查看>>
第二阶段冲刺(2)
查看>>
ajax post 传参
查看>>