springboot2多环境配置与部署

使用jpa操作数据库,最终实现根据不同 的配置文件读取不同的数据源(数据库,缓存以及其他配置信息)

本文主要介绍的是多环境配置与部署,所以关于其他配置就简略的叙述

多环境配置

主配置application.properties(公共部分可以写在主配置,其他环境单独写配置文件,在主配置使用spring.profiles.active激活)

#配置选择需要的环境
#--------开发
#spring.profiles.active=dev
#--------测试
spring.profiles.active=test

###用户名
spring.datasource.username=root
###密码
spring.datasource.password=1234
###驱动
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

 开发环境application-dev.properties

### mysql连接信息
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/dev

测试环境application-test.properties 

### mysql连接信息
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test

部署(由于内置tomcat部署jar包即可,所以没有配置idea的tomcat发布war包,按照spring规范来的,当然打成war包方式也可以,那不是这篇文章需要说明的,请自行百度)

配置jetty(把默认的tomcat排除后再添加依赖)

<!--排除依赖tomcat-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--配置jetty服务器-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>

控制台倒数第二行显示jetty启动成功即可

Jetty started on port(s) 8080 (http/1.1) with context path '/'
扫描二维码关注公众号,回复: 9345896 查看本文章
发布了57 篇原创文章 · 获赞 33 · 访问量 814万+

猜你喜欢

转载自blog.csdn.net/wozniakzhang/article/details/87900459