初识Spring

01 | Spring课程介绍

02 | 一起认识Spring家族的主要成员

https://spring.io/projects

03 | 跟着Spring了解技术趋势

了解 Kotlin。

WebFlux 全面落地尚需时日。

Velocity不维护了,过时的框架。

在判断是否该使用这个框架,或者技术是,可以了解下它的社区和使用人群,是否活跃等。

04 | 编写你的第一个Spring程序

@SpringBootApplication
@RestController
public class HelloSpringApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloSpringApplication.class, args);
    }


    @RequestMapping("/hello")
    public String hello() {
        return "Hello Spring!";
    }
}
# 访问接口
curl localhost:8080/hello

# 访问健康检查
curl localhost:8080/actuator/health

打包:

mvn clean package

源包:不包含依赖   , 完整包:包含所有依赖,可直接运行

maven的install和package的区别:

package可以理解成简单的打包,而install除了打包还会把这个包安装到maven仓库中去。

运行携带依赖的jar包: java -jar hello-spring-0.0.1-SNAPSHOT.jar

maven dependencies与dependencyManagement的区别

  • dependencies即使在子项目中不写该依赖项,那么子项目仍然会从父项目中继承该依赖项(全部继承)

  • dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显示的声明需要用的依赖。如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom;另外如果子项目中指定了版本号,那么会使用子项目中指定的jar版本。
<!-- 如果项目需要有自己的parent,不能使用spring-boot作为parent,则使用dependencyManagement的方式注入spring-boot依赖 -->
    <!--
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>2.3.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    -->


    <!-- 如果项目需要有自己的parent,不能使用spring-boot作为parent,指定mvn打包是在调用spring-boot:repackage时才介入 -->
    <!-- <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.1.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    -->

相关代码:

https://github.com/wuguokai/Spring-Advance/tree/master/hello-spring

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值