I wanted to integrate application insights into my spring boot application**(v3.x.x)** and for that I have used below dependency in my build.gradle.
implementation 'com.microsoft.azure:applicationinsights-spring-boot-starter:2.6.4'
In my controller, I have injected TelemetryClient bean like:
@RestController
@RequestMapping("/")
public class UserController {
@Autowired
TelemetryClient telemetryClient;
@GetMapping("/greetings")
public String greetings() {
// send event
telemetryClient.trackEvent("URI /greeting is triggered");
return "Hello World!";
}
}
And, To connect to my azure app insights I used :
APPLICATIONINSIGHTS_CONNECTION_STRING=somevalue
as Environment variable while running application in IntellijIdea.
Now, Application runs and complains about:
***************************
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.
But, as soon as I downgrade my spring boot version from 3.x.x to 2.7.11, it works fine with the same piece of code and starts the application.
Has anyone else also has experienced similar issue of appinsights with spring boot on 3.x.x ? or Any idea of its fix in latest spring boot version ?
2
Answers
This issue has been resolved in https://github.com/microsoft/ApplicationInsights-Java/issues/3016
Below dependency is compatible with spring boot 3.x:
After that TelemetryClient Bean can be injected like:
I have tried with the same dependency with spring boot 3.x.x version, and I got the same error:
Result:
I was getting the same error as you mentioned above:
3.x.x
yet. The latest compatible version is2.7.x
.3.0.0-beta.1
and it is compatible only with spring boot2.x.x
version.2.x.x
versions rather than using3.x.x
.References:
Refer to github issue regarding the release of Application Insights SpringBoot Starter library.