“初到公司公司用的框架是spingboot,所以要求我们将熟练掌握springboot!所以这些为算是学习笔记,有什么错误请大家指出谢谢!
进入正题,先来讲一个什么是springboot!
解释:Spring Boot(英文中是“引导”的意思),是用来简化Spring应用的搭建到开发的过程,从而使开发人员不需要定义样板化的配置,注意我们需要了解是Spring Boot并不是对spring功能的增强,而是提供了对他快速使用的一种方式,简单的说就是对使用spring做了简化!
spring boot的特征
1:创建了独立的spring的应用程序;
2:嵌入的tomcat,不需要部署war文件;
3.简化了maven的配置;
4:自动配置spring;
5:提供生产就绪的功能,比如指标,外部配置和健康检查;
6:方便开箱即用,没有代码生成,也不需要xml配置;
大家可以结合之前的使用spring和现在用springboot开发做个简单地对比!有利于我们更好的了解springboot
下面请看第一个springboot实例;
步骤:
1:idea创建maven项目;
2:引入架包到pom.xml
?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>com.springboot.hello</artifactId>
<version>1.0-SNAPSHOT</version>
<!--
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>
<!-- 指定一下jdk的版本 ,这里我们使用jdk 1.8 ,默认是1.6 -->
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--
spring-boot-starter-web: 提供了spring的 `` MVC,AOP的依赖包....
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
</textarea>
3:创建一个启动类Application;
package com.ttxs.service;
import org.apache.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Created by john on 2017-04-28.
*/
@SpringBootApplication //声明这是一个springboot,是一个启动入口
public class Application {
//创建日志信息记录;并加载启动入口类;
private static Logger logger = Logger.getLogger(Application.class);
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
logger.info("springboot启动成功");
}
}
4:写一个constroller
package com.ttxs.service.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by john on 2017-04-28.
*/
@RestController //这里使用@RestController这个注解是spring4的注解相当于@Controller和@RequestBody
public class HelloController {
/**
* requestmapping注解是请求映射的路径;
* @return
*/
@RequestMapping("/hello")
public String hello(){
return "helloword";
}
}
访问方式: http://localhost:8080/hello