SpringBoot+vue信息管理系统(2)

本文详细介绍了SpringBoot的基础配置,包括spring-boot-starter-parent提供的默认配置、SpringBootApplication注解解析、自定义banner以及Web容器的配置,如Tomcat、HTTPS、Jetty和Undertow。还探讨了Properties和YAML配置、Profile的使用,以及如何进行环境切换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spring Boot基础配置

1、spring-boot-starter-parent提供默认的配置:

  • Java版本默认使用1.8
  • 编码格式默认使用utf-8
  • 提供Dependency Management 进行项目依赖的版本管理
  • 默认的资源过滤与插件配置

spring-boot-starter-parent 虽然方便,但是在公司开发微服务项目或者多模块项目时一般需要使用公司自己的parent,这时候的parent,这时候如果想进行项目依赖版本的统一管理,就需要使用到Dependency Management ,在pom.xml添加:

<!--<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.0.4.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>-->

此时,就不用继承spring-boot-starter-parent,但是Java版本、编码的格式等都需要开发者手动配置,只需要在pom.xml添加plugin

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

至于编码格式,如果项目是springBoot项目,那么编码会默认加上;但是如果项目只是简单的maven项目,就需要在pom.xml加入:

<properties>
       
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

2、注解SpringBootApplication解析

SpringBootApplication实际上是一个组合注解:

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
		@ComponentScan.Filter(type = FilterType.CUSTOM,classes = TypeExcludeFilter.class),
		@ComponentScan.Filter(type = FilterType.CUSTOM,classes = AutoConfigurationExcludeFilter.class)
})
public class Charpter012Application {

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

}

这个注解由三个注解(SpringBootConfiguration,EnableAutoConfiguration、ComponentScan)组成:

(1)SpringBootConfiguration定义:

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
public @interface SpringBootConfiguration {
    @AliasFor(
        annotation = Configuration.class
    )
    boolean proxyBeanMethods() default true;
}

SpringBootConfiguration的功能就是表面这是一个配置类,开发者可以在这个类中配置bean。从这个角度来讲,这个类所扮演的角色类似于Spring中ApplicationContext.xml文件中的角色

(2)EnableAutoConfiguration:表示开启自动化配置。Spring Boot中的自动化配置是非扫描侵入式的,在任意时刻,开发者都可以使用自定义配置代替自动化中的某一个配置

(3)ComponentScan:完成包的扫描,也是Spring的功能。由于ComponentScan注解默认扫描的类都位于当前

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值