我想将应用程序洞察力集成到我的 spring boot 应用程序**(v3.x.x)** 中,为此我在我的 build.gradle 中使用了以下依赖项。
implementation 'com.microsoft.azure:applicationinsights-spring-boot-starter:2.6.4'
在我的控制器中,我注入了 TelemetryClient bean,例如:
@RestController
@RequestMapping("/")
public class UserController {
@Autowired
TelemetryClient telemetryClient;
@GetMapping("/greetings")
public String greetings() {
// send event
telemetryClient.trackEvent("URI /greeting is triggered");
return "Hello World!";
}
}
而且,为了连接到我使用的 azure app insights:
APPLICATIONINSIGHTS_CONNECTION_STRING=somevalue
在 IntellijIdea 中运行应用程序时作为环境变量。
现在,应用程序运行并抱怨:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field telemetryClient in com.example.demo.app.insights.UserController required a bean of type 'com.microsoft.applicationinsights.TelemetryClient' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.microsoft.applicationinsights.TelemetryClient' in your configuration.
但是,一旦我将我的 spring boot 版本从 3.x.x 降级到 2.7.11,它就可以使用相同的代码正常工作并启动应用程序。
有没有其他人在 3.x.x 上也遇到过与 spring boot 类似的 appinsights 问题?或者对它在最新的 spring boot 版本中的修复有什么想法吗?