回顾Spring框架
Spring框架扩展技术
Spring-Data技术
扩展了Spring数据库访问能力,可以访问Redis、MongoDB、JPA等等。
SpringBoot技术
简化了Spring配置,快速开发Spring应用。(敏捷开发技术)
SpringCloud技术
可以搭建云服务。(微服务架构、REST服务)
MAVEN工具
MAVEN简介
MAVEN是一个项目构建工具。通过maven可以创建项目、编译、jar包管理、打包、发布等一系列工作。
- mvn archetype:generate 创建Maven项目
- mvn compile 编译源代码
- mvn deploy 发布项目
- mvn test-compile 编译测试源代码
- mvn test 运行应用程序中的单元测试
- mvn clean 清除项目目录中的生成结果
- mvn package 根据项目生成的jar
- mvn install 在本地Repository中安装jar
MAVEN安装和配置
- 下载apache-maven.zip工具包,解压
- 修改con/settings.xml,指向中央仓库(指定了阿里的)
- 将MAVEN和Eclipse集成配置
选择Eclipse的Window-->Preferences窗口,设置下面两个界面.
MAVEN使用
Eclipse右键新建maven--》maven project
如果创建的是war类型工程,会提示有错,需要生成web.xml
Spring Boot环境搭建
SpringBoot是对Spring框架的封装,实现了Spring应用的快速开发,可以使用IOC、AOP、MVC以及跟其他技术整合。去除了XML配置文件,一切采用Java配置(注解)。
-
创建Maven Project添加boot开发包
pom.xml添加下面定义
<!-- spring boot基础包 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.7.RELEASE</version> </parent> <dependencies> <!-- boot核心包,包含自动配置,ioc,yaml解析 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- mvc、rest --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
-
添加boot配置文件(application.properties或application.yml)
-
application.properties
spring.datasource.name=scott spring.datasource.password=12345
-
application.yml
spring: datasource: name: scott password: 12345
案例:
server.port=8888 server.context-path=/boot01
-
-
主启动类
@SpringBootApplication public class MyBootApplication { public static void main(String[] args){ SpringApplication.run(MyBootApplication.class, args); } }
-
编写Controller
@RestController //@Controller+@ResponseBody public class HelloController { @RequestMapping("/hello/{name}") public String say(@PathVariable("name")String name){ return "Hello World "+name; } }
-
运行MyBootApplication主启动类,启动boot内置的tomcat
打开浏览器输入:http://localhost:8888/boot01/hello/scott