springBoot01_新建项目、简化部署

本文详细介绍SpringBoot作为JAVAEE的全面解决方案,从快速构建应用到分布式处理,再到流式计算与批处理的全过程。通过具体步骤演示如何使用SpringBoot、SpringCloud及SpringCloudDataFlow等工具,实现从maven配置到IDEA中项目搭建,直至应用的部署与运行。不仅覆盖了SpringBoot的基础知识,还深入探讨了其在大型应用中的实践。

在这里插入图片描述
springBoot是JAVAEE整个的解决方案,一站式解决
在这里插入图片描述
在这里插入图片描述
入门容易,精通难
需要了解spring核心框架
在这里插入图片描述
如何构建大型应用?
使用springBoot快速构建
如何在大型的应用网之间互调呢?
使用SpringCloud分布式
如何做流式计算、批处理
使用SpringCloud Data Flow

在这里插入图片描述
前置内容
在这里插入图片描述
在这里插入图片描述

maven配置

给maven 的settings.xml配置文件的profiles标签添加

<profile>
	  <id>jdk-1.8</id>
	  <activation>
		<activeByDefault>true</activeByDefault>
		<jdk>1.8</jdk>
	  </activation>
	  <properties>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
	  </properties>
	</profile>

IDEA中maven设置成本地的

在这里插入图片描述

springboot helloworld

1、新建maven工程

2、导入springBoot依赖

可以从官网生成一个springboot项目
在这里插入图片描述
copy依赖到pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

3、编写主程序,启动springBoot应用

/**
        * 标注是主程序类,说明是springBoot应用
        */
@SpringBootApplication
public class HelloWorldMainApplication {

    public static void main(String[] args) {
        //Spring应用启动起来
        SpringApplication.run(HelloWorldMainApplication.class, args);
    }
}

4、编写Controller、service

@Controller
public class HelloController {

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return "Hello World";
    }
}

5、main方法启动

在这里插入图片描述
浏览器输入http://localhost:8080/
在这里插入图片描述
响应hello请求
http://localhost:8080/hello
在这里插入图片描述

不需要那些配置就启动了项目,说明它内置了tomcat

简化部署

首先导入maven插件,可以将应用打包成一个可执行jar包

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

在这里插入图片描述
打包后得到jar包
在这里插入图片描述
把它拷贝出来测试一下,比如放到桌面
在这里插入图片描述
使用java -jar命令来启动项目
在这里插入图片描述
一样可以访问

我们可以打开jar包看看内部
有自己写的类编译后的class文件
在这里插入图片描述
lib下就是项目以来的所有jar包,都包含了
其中有一个内置的tomcat也导入了,所以项目运行不再需要外部配置tomcat,非常方便
在这里插入图片描述

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值