springboot 基础(一)

SpringBoot(主流)

1.敏捷开发(整合框架),弊端(不方便扩展)

2.无需tomcat(java应用程序运行,实际是jar包),内置Tomcat

3.减少xml配置(没有xml),采用配置文件properties

4.SpringClound+SpingBoot

5.注解

推荐网站:http://bbs.itmayiedu.com/


springboot 和微服务有什么样的关联?

目前来说springClound(http接口+rest),基于SpringBoot web组件封装SpringMVC(不能封装Struts2)


新建名为”springboot-helloworld” 类型为Jar工程项目

1.选择jar类型

2.引入依赖

 
 

//引入springboot父类依赖,把常用的依赖包,自动依赖过来

<parent>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-parent</artifactId>

    <version>1.3.3.RELEASE</version>

</parent>

<dependencies>

  <!—引入SpringBoot-web 组件 自动整合SpringMVC+Spring+Mybatis

不要写版本号,springboot自动解决版本冲突-->

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-web</artifactId>

    </dependency>

</dependencies>


思考:SpringBoot封装jar依赖原理

Maven--继承依赖关系  通过点击

<artifactId>spring-boot-starter-parent</artifactId>
进入父级
<artifactId>spring-boot-dependencies</artifactId>

这里是版本号定义,下边是Maven包定义

所有的jar全部都在parent

spring-boot-starter-parent作用

在pom.xml中引入spring-boot-start-parent,spring官方的解释叫什么stater poms,它可以提供dependency management,也就是说依赖管理,引入以后在申明其它dependency的时候就不需要version了,后面可以看到。

spring-boot-starter-web作用

springweb 核心组件

spring-boot-maven-plugin作用

 如果我们要直接Main启动spring,那么以下plugin必须要添加,否则是无法启动的。如果使用maven 的spring-boot:run的话是不需要此配置的。

3.使用springboot写第一个接口(服务)

@RestController
@EnableAutoConfiguration
public class HelloController {
	@RequestMapping("/hello")
	public String index() {
		return "Hello World";
	}	
public static void main(String[] args) { 
        //主函数运行springboot项目
        SpringApplication.run(HelloController.class, args);
	}
}

a、@RestController

在上加上RestController 表示修饰该Controller所有的方法返回JSON格式,直接可以编写

Restful接口

b@EnableAutoConfiguration

注解:作用在于让 Spring Boot   根据应用所声明的依赖来对 Spring 框架进行自动配置
        这个注解告诉Spring Boot根据添加的jar依赖猜测你想如何配置Spring。由于spring-boot-starter-web添加了Tomcat和Spring MVC,所以auto-configuration将假定你正在开发一个web应用并相应地对Spring进行设置。

c、SpringApplication.run(HelloController.class, args);

   标识为启动类.


猜你喜欢

转载自blog.csdn.net/fwk19840301/article/details/80249236