从零开始学springboot笔记(一)-Spring boot之Hello Word

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

然后再pom文件中添加相关依赖和配置,具体如下: 
 <!-- 
    spring boot 父节点依赖,引入这个之后相关的引入就不需要添加version配置,spring boot会自动选择最合适的版本进行添加。
  -->
  <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>1.4.1.RELEASE</version>
  </parent>


  <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <java.version>1.8</java.version>
  </properties>

  <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>

注意添加依赖后,记得update;
然后创建HelloController,code如下:
import java.util.Date;

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

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String hello(){
        
        return "hello";
    }
}

然后编码springboot启动类App.java

@SpringBootApplication
public 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: default
2019-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 hierarchy
2019-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 Tomcat
2019-05-27 15:27:54.099  INFO 2020 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.5
2019-05-27 15:27:54.180  INFO 2020 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-05-27 15:27:54.180  INFO 2020 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1198 ms
2019-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 hierarchy
2019-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<java.util.Map<java.lang.String, java.lang.Object>> 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 startup
2019-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/xh_Blog/p/10931105.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1.1 前言 1.2 资料官网 1.3 spring boot起步之Hello World 1.4 Spring Boot返回json数据 1.5 Spring Boot热部署 1.6 Spring Boot使用别的json解析框架 1.7 全局异常捕捉 1.8 Spring Boot datasource - mysql 1.9 JPA - Hibernate 1.10 使用JPA保存数据 1.11 使用JdbcTemplate 1.12 Spring Boot修改端口号 1.13 Spring Boot配置ContextPath 1.14 Spring Boot改变JDK编译版本 1.15 处理静态资源(默认资源映射) 1.16 处理静态资源(自定义资源映射) 1.17 Spring Boot定时任务的使用 1.18 Spring Boot使用Druid和监控配置 1.19 Spring Boot使用Druid(编程注入) 1.20 Spring Boot普通类调用bean 1.21 使用模板(thymeleaf-freemarker) 1.22 Spring Boot 添加JSP支持 1.23 Spring Boot Servlet 1.24 Spring Boot过滤器、监听器 1.25 Spring Boot 拦截器HandlerInterceptor 1.26 Spring Boot启动加载数据CommandLineRunner 1.27 Spring Boot环境变量读取和属性对象的绑定 1.28 Spring Boot使用自定义的properties 1.29 改变自动扫描的包 1.30 Spring Boot Junit单元测试 1.31 SpringBoot启动时的Banner设置 1.32 Spring boot 文件上传(多文件上传) 1.33 导入时如何定制spring-boot依赖项的版本 1.34 Spring Boot导入XML配置 1.35 Spring Boot使用@SpringBootApplication注解 1.36 Spring Boot 监控和管理生产环境 1.37 Spring Boot的启动器Starter详解 1.38 Spring Boot集成Redis实现缓存机制 1.39 Spring Boot Cache理论篇 1.40 Spring Boot集成EHCache实现缓存机制 1.41 Spring Boot分布式Session状态保存Redis 1.42 Spring Boot Shiro权限管理 1.43 Spring Boot Shiro权限管理 1.44 Spring Boot Shiro权限管理 1.45 Spring Boot Shiro权限管理

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值