pom.xml

    <name>springboot-application</name>
    <description>A project for Spring Boot</description>
    <!- 提供相关的Maven默认依赖,常用的包依赖可以省去version标签 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

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

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--热加载-->
<!--    手动:修改完代码,按快捷键Ctrl+F9,手动构建项目,或者只修改单个类文件的话,按Ctrl+Shift+F9,重新编译该类文件,即可触发重启服务。-->
<!-- 自动 3-->

<!-- 1. File -> Settings -> Compiler,勾选 Build Project automatically-->

<!-- 2. 按快捷键Ctrl+Shift+Alt+/,选择1.Registry...-->

<!-- 3. 勾选 compiler.automake.allow.when.app.running 即可-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    </dependencies>

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

 

 启动类


@SpringBootApplication
public class ApplicationVastStart {
    public static void main(String[] args) {
        SpringApplication.run(ApplicationVastStart.class, args);
    }
Registrar是抽象类AutoConfigurationPackages的内部静态类,Registrar内的方法registerBeanDefinitions负责将获取到的注解所在的包及其子包下的所有组件注册进容器。

SpringBoot的启动类要在其他类的父包或在同一个包中

 

多个环境配置文件

在现实的开发环境中,我们需要不同的配置环境;格式为application-{profile}.properties,其中{profile}对应你的环境标识,比如:

  • application-test.yml:测试环境
  • application-dev.yml:开发环境
  • application-prod.yml:生产环境

怎么使用?只需要我们在application.yml中加:

 spring:
  profiles:
    active: dev
 

其中application-dev.yml:

 server:
  port: 8082
 

启动工程,发现程序的端口不再是8080,而是8082。

 

posted on 2019-12-06 17:18  风又奈何  阅读(329)  评论(0编辑  收藏  举报