springboot第一天

1.导入相关starter

2.配置yml配置文件

3.创建主启动类

4.通过注解启动相关功能

5.运行主启动类

springboot的工程打jar包就ok

<!-- 继承SpringBoot官方指定的父工程 -->   
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.8.RELEASE</version>
</parent>

1.1加入场景启动器

<dependencies>
    <!-- 加入Web开发所需要的场景启动器 -->
    <dependency>
        <!-- 指定groupId和artifactId即可,版本已在父工程中定义 -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

ALT+F5自动导入maven更新依赖

创建主启动类

package com.pyq;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication //表示是一个springboot工程
public class SpringBootDemo {
	public static void main(String[] args) {
		SpringApplication.run(SpringBootDemo.class,args);
	}
}

创建控制器

package com.pyq.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloHandler {

	@ResponseBody
	@RequestMapping("/hello/spring/boot")
	public String helloSpringBoot() {
		return "Hello SpringBoot";
	}
}


然后直接可以启动成功

修改日志里面的启动图标
阅读启动日志

2020-04-13 10:26:32.038  INFO 186392 --- [           main] com.pyq.SpringBootDemo                   : Starting SpringBootDemo on Janker with PID 186392 (D:\pyq20workspace\zhongchouweb01\springboot-web\target\classes started by Administrator in D:\pyq20workspace\zhongchouweb01\springboot-web)
2020-04-13 10:26:32.040  INFO 186392 --- [           main] com.pyq.SpringBootDemo                   : No active profile set, falling back to default profiles: default
2020-04-13 10:26:32.074  INFO 186392 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5606c0b: startup date [Mon Apr 13 10:26:32 CST 2020]; root of context hierarchy
2020-04-13 10:26:32.881  INFO 186392 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2020-04-13 10:26:32.888  INFO 186392 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-04-13 10:26:32.889  INFO 186392 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.23
2020-04-13 10:26:32.955  INFO 186392 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-04-13 10:26:32.955  INFO 186392 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 885 ms
2020-04-13 10:26:33.071  INFO 186392 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2020-04-13 10:26:33.074  INFO 186392 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2020-04-13 10:26:33.075  INFO 186392 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2020-04-13 10:26:33.075  INFO 186392 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2020-04-13 10:26:33.075  INFO 186392 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2020-04-13 10:26:33.309  INFO 186392 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5606c0b: startup date [Mon Apr 13 10:26:32 CST 2020]; root of context hierarchy
2020-04-13 10:26:33.354  INFO 186392 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello/spring/boot]}" onto public java.lang.String com.pyq.controller.HelloHandler.helloSpringBoot()
2020-04-13 10:26:33.357  INFO 186392 --- [           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)
2020-04-13 10:26:33.357  INFO 186392 --- [           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)
2020-04-13 10:26:33.377  INFO 186392 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-13 10:26:33.377  INFO 186392 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-13 10:26:33.406  INFO 186392 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-13 10:26:33.500  INFO 186392 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2020-04-13 10:26:33.540  INFO 186392 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2020-04-13 10:26:33.544  INFO 186392 --- [           main] com.pyq.SpringBootDemo                   : Started SpringBootDemo in 1.732 seconds (JVM running for 3.018)
2020-04-13 10:29:08.052  INFO 186392 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2020-04-13 10:29:08.053  INFO 186392 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2020-04-13 10:29:08.073  INFO 186392 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 20 ms

第二种创建方法

下载中

重要注解

主启动类上书写注解

@ComponentScan("com.pyq.handler.apple")

配置文件

properties 和 yml格式的配置文件后缀
applicaation.properties
server.prot= 空格+端口号
server.setvlet.context-path=/路径名称
C:\Users\Administrator.m2\settings.xml

        <properties>
		<java.version>1.8</java.version>
		<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
	</properties>

这样可以解决相关maven的问题

加入mybatis的依赖配置信息

posted @ 2020-04-13 14:37  dev-pan  阅读(26)  评论(0编辑  收藏  举报