探索 IntelliJ IDEA 中 Spring Boot 运行配置选项及其作用

IntelliJ IDEA 作为一款功能强大的集成开发环境(IDE),为 Spring Boot 应用提供了丰富的运行配置选项,帮助开发者便捷地启动、调试和监控应用。本篇博客将逐一解析这些选项及其在 Spring Boot 开发中的作用。

通用选项

Active profiles

作用:指定应用启动时要激活的 Spring 配置文件。这些配置文件(通常以 -profile.yml-profile.properties 结尾)可以按需覆盖主配置文件中的属性,实现环境特定的配置。

示例:添加 devlocal,则应用会同时激活 application-dev.ymlapplication-local.yml 中的设置。

Enable debug output (-Ddebug)

作用:启用 Spring Boot 的调试输出模式,增加日志级别至 DEBUG,以便查看更详细的框架内部信息和日志。

Hide banner (-Dspring.main.banner-mode=OFF)

作用:关闭 Spring Boot 启动时显示的 ASCII 图形欢迎界面,使控制台输出更加简洁。

Disable launch optimization (XX:TieredStopAtLevel=1 -noverify)

作用:禁用 Java 虚拟机(JVM)的启动优化,便于更快地启动应用进行调试。但请注意,生产环境中通常不建议禁用这些优化。

Disable JMX agent

作用:取消启用 Java 管理扩展(JMX)代理,避免远程监控和管理功能。在不需要 JMX 监控的情况下,禁用它可减少资源消耗和潜在的安全风险。

更新与停靠行为

On ‘Update’ action: Do nothing

作用:当选择“更新”运行配置时,IDE 不执行任何操作。适用于不需要自动重新部署的应用场景。

On frame deactivation: Do nothing

作用:当 IDE 窗口失去焦点时,不对运行中的应用采取任何动作。避免因误操作导致应用停止。

配置属性覆盖

Override configuration properties

作用:允许直接在运行配置中临时覆盖应用的 Spring Boot 属性。这对于快速验证特定配置更改或在不同环境中运行应用非常有用。

运行环境设置

Allow multiple instances

作用:允许同时运行同一应用的多个实例,每个实例使用独立的运行配置。

Working directory

作用:指定应用的运行工作目录,影响相对路径的解析以及日志、临时文件等的存放位置。

Environment variables

作用:设置应用运行时的环境变量,影响应用的行为和依赖组件的配置。

Do not build before run

作用:取消运行前自动构建项目,适用于已确保代码编译无误,或希望手动控制构建时机的情况。

Use classpath of module

作用:指定使用哪个模块的类路径来运行应用,适用于多模块项目。

Add VM options

作用:添加 JVM 参数,如内存分配(-Xms-Xmx)、垃圾收集器选择、系统属性等,以调整 JVM 行为。

Program arguments

作用:为应用主类传递命令行参数,供应用代码在运行时读取和使用。

Add dependencies with “provided” scope to classpath

作用:将依赖管理中 provided 作用域的依赖项添加到运行时类路径,确保依赖的 Servlet 容器等外部环境提供的库在 IDE 中也能正常工作。

Shorten command line

作用:启用命令行长度优化,通过使用响应文件避免因类路径过长导致的命令行限制问题。

Specify logs to be shown in console

作用:指定哪些日志文件的内容应在控制台显示,方便实时监控应用日志。

Save console output to file

作用:将控制台输出保存到指定文件,便于后期分析和排查问题。

Show console when a message is printed to stdout/stderr

作用:当标准输出(stdout)或标准错误输出(stderr)有内容打印时自动打开控制台窗口。

类与包过滤

Specify classes and packages

作用:指定应用启动时只扫描和加载特定的类和包,加速启动过程,适用于大型项目或测试特定模块。

Exclude classes and packages

作用:排除应用启动时不应扫描和加载的类和包,避免不必要的处理和潜在冲突。

Specify alternative coverage runner

作用:选择替代的代码覆盖率工具,如 JaCoCo、Cobertura 等,用于测试覆盖率分析。

Use tracing

作用:启用 JVM 跟踪功能,生成详细的 JVM 执行轨迹文件(.trc),用于性能分析。

Collect coverage in test folders

作用:在测试代码目录下收集代码覆盖率数据,而非源码目录,便于区分测试与生产代码的覆盖率。

预启动任务

Add before launch task

作用:配置应用启动前需要执行的任务,如编译、Maven/Gradle 构建、数据库迁移等。

运行视图与提示

Open run/debug tool window when started

作用:启动应用后自动打开运行/调试工具窗口,便于观察应用状态和控制运行。

Show the run/debug configuration settings before start

作用:在应用启动前显示当前运行配置的详细设置,确认无误后再启动。

总结,IntelliJ IDEA 提供的 Spring Boot 运行配置选项赋予了开发者精细控制应用运行环境、日志输出、依赖管理、类加载策略、预启动任务等方方面面的能力,极大地提升了开发效率和灵活性。了解并合理运用这些选项,能使 Spring Boot 开发体验更加顺畅。

  • 12
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring.Boot.in.Action.2015.12.pdfFor online information and ordering of this and other manning books, please visit www.manning.com.thepublisheroffersdiscountsonthisbookwhenorderedinquantity For more information, please contact Special sales department Manning publications co 20 Baldwin Road PO BoX 761 Shelter island. ny11964 Emailorders@manning.com @2016 by manning Publications Co. All rights reserved No part of this publication may be reproduced, stored in a retrieval system, or transmitted,in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and manning Publications was aware of a trademark claim, the designations have been printed in initial caps ll Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine Manning publications co Development editor: Cynthia Kane 20 Baldwin Road Technical development editor: Robert casazza PO BoX 761 Copyeditor: Andy Carroll Shelter island. ny11964 Proofreader: Corbin Collins Technical p der John Guthrie Typesetter: Gordan Salinovic Cover designer: Marija Tudor ISBN9781617292545 Printed in the united states of america 12345678910-EBM-201918171615 contents reword vii pre eface 2x about this book xii acknowledgments xu Bootstarting Spring I 1. 1 Spring rebooted Taking a fresh look at spring 2. Examining spring Boot essentials 4 What Spring Boot isn't 7 1.2 Getting started with Spring boot 8 Installing the spring boot cli 8 Initializing a spring boot project with Spring Initializr 12 3 Summary 22 Developing your first Spring Boot application 23 2.1 Putting spring boot to work 24 Examining a newly initialized spring boot project 26 Dissecting Bc iect build 30 2.2 USing starter dependencies 33 Specifying facet-based dependencies 34. Overriding starter transitive dependencies 35 CONTENTS 2.8 USing automatic configuration 37 Focusing on application functionality 37. Running the application 45. What just happened? 45 2.4 Summary 48 Customizing configuration 49 8.1 Overriding Spring Boot auto-configuration 50 Securing the application 50. Creating a custom security configuration 51. Taking another peek under the covers of auto-configuration55 8.2 Externalizing configuration with properties 57 Fine-tuning auto-configuration 58. Externally configuring application beans 64. Configuring with profiles 69 8.8 Customizing application error pages 71 3.4 Summary 74 Testing with Spring Boot 76 4.1 Integration testing auto-configuration 77 4.2 Testing web applications 79 Mocking spring MvC 80- Testing web security 83 4.3 Testing a running application 86 Starting the server on a random port 87. Testing HTML pages with selenium 88 4.4 Summary 90 Getting Groovy with the spring Boot CLI 92 5.1 Developing a Spring Boot CLI application 93 Setting up the cli project 93 Eliminating code noise with Groovy 94. What just happened? 98 5.2 Grabbing dependencies 100 Overriding default dependency versions 101. Adding dependency repositories 102 5.8 Running tests with the CLI 102 5.4 Creating a deployable artifact 105 5.5 Summary 106 CONTENTS 6 Applying Grails in Spring Boot 107 1 Using gorm for data persistence 108 2 Defining views with groovy server pages 113 6.3 Mixing spring boot with grails 3 115 Creating a new grails project 116 Defining the domain 118 Writing a grails controller 119. Creating the view 120 6.4 Summary 123 Taking a peek inside with the Actuator 124 7.1 Exploring the actuator's endpoints 125 Viewing configuration details 126. Tapping runtime metrics 133 Shutting down the application 139. Fetching application information 140 7.2 Connecting to the Actuator remote shell 141 Viewing the autoconfig report 142. Listing application beans 143 Watching application metrics 144.Invoking actuator endpoints 145 7. 3 Monitoring your application with JMX 146 7.4 Customizing the Actuator 148 Changing endpoint Ds 148 Enabling and disabling endpoints 149 Adding custom metrics and gauges 149- Creating a custom trace repository 153 Plugging in custom health indicators 155 7.5 Securing Actuator endpoints 156 7.6 Summary 159 8 Deploying Spring Boot applications 160 8.1 Weighing deployment options 161 8.2 Deploying to an application server 162 Building a WaRfile 162 Creating a production profile Enabling database migration 168 8.3 Pushing to the cloud 173 Deploying to Cloud Foundry 173 Deploying to Heroku 177 8. Summary 180 appendix a spring Boot developer Tools 187 appendix b spring Boot starters 188 appendix c Configuration properties 195 appendix d spring boot dependencies 232 index 243 In the spring of 2014, the Delivery Engineering team at Netflix set out to achieve a lofty goal: enable end-to-end global continuous delivery via a software platform that facilitates both extensibility and resiliency. my team had previously built two different applications attempting to address Netflix's delivery and deployment needs, but both were beginning to show the telltale signs of monolith-ness and neither met the goals of flexibility and resiliency. What's more, the most stymieing effect of these monolithic applications was ultimately that we were unable to keep pace with our partner's inno- vation. Users had begun to move around our tools rather than with them It became apparent that if we wanted to provide real value to the company and rap- idly innovate, we needed to break up the monoliths into small, independent services that could be released at will. Embracing a microservice architecture gave us hope that we could also address the twin goals of flexibility and resiliency. but we needed to do it on a credible foundation where we could count on real concurrency, legitimate moni- toring, reliable and easy service discovery, and great runtime performance With the jVM as our bedrock, we looked for a framework that would give us rapid velocity and steadfast operationalization out of the box. We zeroed in on Spring Boot Spring Boot makes it effortless to create Spring-powered, production-ready ser- vices without a lot of code! Indeed, the fact that a simple Spring Boot Hello World application can fit into a tweet is a radical departure from what the same functionality required on the vm only a few short years ago. Out-of-the-box nonfunctional features like security, metrics, health-checks, embedded servers, and externalized configura tion made boot an easy choice for us FOREWORD Yet, when we embarked on our Spring boot journey solid documentation was hard to come by. Relying on source code isnt the most joyful manner of figuring out how to properly leverage a frameworks features It's not surprising to see the author of mannings venerable Spring in Action take on the challenge of concisely distilling the core aspects of working with Spring Boot into another cogent book. Nor is it surprising that Craig and the Manning crew have done another tremendously wonderful job! Spring Boot in Action is an easily readable book, as weve now come to expect from Craig and manning From chapter Is attention-getting introduction to Boot and the now legend ary 9Oish-character tweetable Boot application to an in-depth analysis of Boots Actuator in chapter 7, which enables a host of auto-magical operational features required for any production application, Spring Boot in Action leaves no stone unturned. Indeed, for me, chapter 7's deep dive into the Actuator answered some of the lingering questions I've had in the back of my head since picking up Boot well over a year ago. Chapter 8s thor- ough examination of deployment options opened my eyes to the simplicity of cloud Foundry for cloud deployments. One of my favorite chapters is chapter 4, where Craig explores the many powerful options for easily testing a Boot application. From the get- o, I was pleasantly surprised with some of Springs testing features, and boot takes g advantage of them nicely As I've publicly stated before, Spring Boot is just the kind of framework the Java community has been seeking for over a decade. Its easy-to-use development features and out-of-the-box operationalization make java development fun again I,m pleased to report that Spring and spring boot are the foundation of Netflix's new continuous delivery platform. What's more, other teams at Netflix are following the same path because they too see the myriad benefits of boot It's with equal parts excitement and passion that I absolutely endorse craigs book as the easy-to-digest and fun-to-read Spring boot documentation the Java community has been waiting for since Boot took the community by storm. Craigs accessible writ- ing style and sweeping analysis of boot's core features and functionality will surely leave readers with a solid grasp of Boot(along with a joyful sense of awe for it) Keep up the great work Craig Manning Publications, and all the brilliant develop ers who have made spring boot what it is today each one of you has ensured a bright future for the JV ANDREW GLOVER MANAGER, DELIVERY ENGINEERING AT NETFLIX preface At the 1964 New York World's Fair, Walt Disney introduced three groundbreaking attractions:"“it' s a small world,”“ Great Moments with mr. Lincoln," and the“ Carouse of Progress " All three of these attractions have since moved into disneyland and walt Disney world, and you can still see them today My favorite of these is the Carousel of Progress. Supposedly, it was one of Walt Disneys favorites too. It's part ride and part stage show where the seating area rotates around a center area featuring four stages. Each stage tells the story of a family at different time periods of the 20th century-the early 1900s, the 1920s the 1940s, and recent times-highlighting the technology advances in that time period The story of innovation is told from a hand-cranked washing machine, to electric lighting and radio, to automatic dishwashers and television, to computers and voice-activated appliances In every act, the father (who is also the narrator of the show)talks about the latest inventions and says "It cant get any better only to discover that in fact, it does get better in the next act as technology progresses Although Spring doesn't have quite as long a history as that displayed in the Car- ousel of Progress, I feel the same way about Spring as"Progress Dad felt about the 20th century. Each and every Spring application seems to make the lives of developers so much better. Just looking at how Spring components are declared and wired together, we can see the following progression over the history of Spring

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值