简体   繁体   English

Spring Boot 2.0 Gradle在IntelliJ中运行和测试

[英]Spring Boot 2.0 Gradle run and test in IntelliJ

I have a simple Spring Boot 2 application with Gradle as build system. 我有一个使用Gradle作为构建系统的简单Spring Boot 2应用程序。 Everything runs fine as long as I use Gradle to run and test the project. 只要我使用Gradle来运行和测试项目,一切就可以正常运行。

One controller class contain an @Autowire d bean 一个控制器类包含一个@Autowire d bean

@Autowired
OAuth2AuthorizedClientService clientService

which works quite ok. 效果还不错。

The problem is, when I try to run the application in IntelliJ IDEA through a right-click on the application class or if I start my test suite, the system complains that the above mentioned bean is missing. 问题是,当我尝试通过右键单击应用程序类在IntelliJ IDEA中运行该应用程序时,或者如果我启动测试套件,则系统会抱怨缺少上述bean。

Just referencing the bean without declaring it seems to be a standard pattern... 只是引用bean而不声明它似乎是一个标准模式。

Any hint on where I could look for a solution? 关于在哪里可以找到解决方案的任何提示?

I think problem cause is run configuration. 我认为问题原因是运行配置。 You can run gradle bootRun by using IntelliJ. 您可以使用IntelliJ运行gradle bootRun as below 如下

Screen shot 屏幕截图

在此处输入图片说明

so, I first thought that the problem is because of a misconfiguration in my project (it tells me that the bean definition is missing) but it seems to be a misconfiguration of IntelliJ which I couldn't verify yet: 因此,我首先认为问题是由于项目中的配置错误(它告诉我缺少bean定义),但似乎是IntelliJ的配置错误,我无法验证:

When you go to the project settings (ALT+Shift+Ctrl+S), there is a facets section. 转到项目设置(ALT + Shift + Ctrl + S)时,会有一个方面部分。 The system should have autoconfigured some Spring facets, but these are not available on my system. 系统应该已经自动配置了一些Spring facet,但是这些在我的系统上不可用。 This seems to be the reason of my problems. 这似乎是我遇到问题的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM