Spring框架回顾 springBoot 火推01


回顾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安装和配置

  1. 下载apache-maven.zip工具包,解压
  2. 修改con/settings.xml,指向中央仓库(指定了阿里的)
  3. 将MAVEN和Eclipse集成配置

选择Eclipse的Window-->Preferences窗口,设置下面两个界面.

MAVEN使用

Eclipse右键新建maven--》maven project

如果创建的是war类型工程,会提示有错,需要生成web.xml

Spring Boot环境搭建

SpringBoot是对Spring框架的封装,实现了Spring应用的快速开发,可以使用IOC、AOP、MVC以及跟其他技术整合。去除了XML配置文件,一切采用Java配置(注解)。

  1. 创建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>
    

  2. 添加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
      
  3. 主启动类

    @SpringBootApplication
    public class MyBootApplication {
    
        public static void main(String[] args){
            SpringApplication.run(MyBootApplication.class, args);
        }
    
    }
    
  4. 编写Controller

    @RestController //@Controller+@ResponseBody
    public class HelloController {
    
        @RequestMapping("/hello/{name}")
        public String say(@PathVariable("name")String name){
            return "Hello World "+name;
        }
    
    }
    
  5. 运行MyBootApplication主启动类,启动boot内置的tomcat

    打开浏览器输入:http://localhost:8888/boot01/hello/scott

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值