IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

SpringBoot实现多环境配置

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

1.为什么需要配置多环境配置

在实际的开发中,我们往往需要在不同的环境中使用不同的数据库、缓存配置,如果使用同一套配置文件,在不同环境部署的时候手动去修改配置文件,会使部署变得很繁琐。使用多环境配置文件可以很方便的实现此功能。

1.创建不同环境的配置文件

在resource文件夹中添加一下配置文件:

application-dev.properties //开发环境配置文件
application-rc.properties //线上环境配置文件
application-test.properties //测试环境配置文件

2. 选择使用的配置文件

在resource/application.properties配置文件中添加一下配置项目:

spring.profiles.active=dev

此配置用于选择使用的配置环境,值为application-{profile}.properties中的profile值。

3.使用命令行选择使用的配置文件

SpringBoot还支持通过命令行的方式修改配置,使用方式如下:

java -jar xxx.jar --spring.profiles.active=dev

其中–spring.profiles.active=dev相当于在application.properties文件中加入了此配置。

4.测试多环境配置

我们分别在

application-dev.properties //开发环境配置文件
application-rc.properties //线上环境配置文件
application-test.properties //测试环境配置文件

文件中添加以下配置:

#端口号
server.port=8081
server.port=8082
server.port=8083

依次修改application.properties文件中的以下配置:

spring.profiles.active=dev、test、rc

修改后依次重启服务。
当使用dev的时候控制台输出一下内容:

    2018-04-10 20:29:23.841  INFO 11492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-04-10 20:29:23.871  INFO 11492 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-04-10 20:29:23.871  INFO 11492 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-04-10 20:29:23.961  INFO 11492 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-04-10 20:29:24.011  INFO 11492 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8081 (http) with context path '/demo'
2018-04-10 20:29:24.011  INFO 11492 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 2.271 seconds (JVM running for 2.608)

使用test的时候控制台输出一下内容:

2018-04-10 20:30:17.458  INFO 12824 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-04-10 20:30:17.498  INFO 12824 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8083 (http) with context path '/demo'
2018-04-10 20:30:17.508  INFO 12824 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 2.268 seconds (JVM running for 2.609)

使用rc的时候输出以下内容:

2018-04-10 20:31:14.302  INFO 11972 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8083 (http) with context path '/demo'
2018-04-10 20:31:14.312  INFO 11972 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 2.133 seconds (JVM running for 2.488)

可以看出在服务启动的时候分别用了不同的配置文件。

文章永久链接:https://tech.souyunku.com/?p=32203


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(92) 打赏



未经允许不得转载:搜云库技术团队 » SpringBoot实现多环境配置

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367