This article is about fixing Application run failed when spring boot project without spring-web dependency in opentracing-contrib Java Spring Cloud
  • 29-Jan-2023
Lightrun Team
Author Lightrun Team
Share
This article is about fixing Application run failed when spring boot project without spring-web dependency in opentracing-contrib Java Spring Cloud

Application run failed when spring boot project without spring-web dependency in opentracing-contrib Java Spring Cloud

Lightrun Team
Lightrun Team
29-Jan-2023

Explanation of the problem

The project uses the following dependencies:

  • Opentracing: groupId: io.opentracing.contrib artifactId: opentracing-spring-jaeger-cloud-starter version: 2.0.0 exclusions: groupId: io.opentracing.contrib artifactId: opentracing-spring-cloud-reactor-starter
  • Spring Boot: groupId: org.springframework.boot artifactId: spring-boot-starter-parent version: 2.1.0.RELEASE

Error log:

  • 10:23:31.366 [main] ERROR org.springframework.boot.SpringApplication:858 – Application run failed
  • BeanCreationException: Error creating bean with name ‘executorBeanPostProcessor’ defined in class path resource [io/opentracing/contrib/spring/cloud/async/DefaultAsyncAutoConfiguration.class]
  • BeanPostProcessor before instantiation of bean failed; nested exception is BeanCreationException: Error creating bean with name ‘org.springframework.cache.annotation.ProxyCachingConfiguration’
  • BeanPostProcessor before instantiation of bean failed; nested exception is BeanCreationException: Error creating bean with name ‘org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration’
  • Initialization of bean failed; nested exception is IllegalArgumentException: error Type referred to is not an annotation type: org$springframework$web$bind$annotation$RestController

Troubleshooting with the Lightrun Developer Observability Platform

Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.

  • Instantly add logs to, set metrics in, and take snapshots of live applications
  • Insights delivered straight to your IDE or CLI
  • Works where you do: dev, QA, staging, CI/CD, and production

Start for free today

Problem solution for Application run failed when spring boot project without spring-web dependency in opentracing-contrib Java Spring Cloud

The error might be caused by missing the spring-web dependency in your Spring Boot project. To resolve this issue, you can add the following dependency to your project’s pom.xml file:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>

This will bring in all necessary components for a web application, including the spring-web module. After adding the dependency, run a maven clean and install, and try running the application again.

Other popular problems with Java Spring Cloud

Problem: NoSuchBeanDefinitionException

The NoSuchBeanDefinitionException is thrown when a required bean cannot be found in the application context. This can happen when a bean is not correctly defined or not correctly added to the application context.

Solution:

To resolve this issue, you need to ensure that the missing bean is defined correctly and added to the application context. This can be done by using the @Component, @Service, @Controller, or @Repository annotation on the class that you want to be a bean and ensuring that it is correctly added to the context using the component scan.

@Service
public class MyService {
  // ...
}
@SpringBootApplication
@ComponentScan(basePackages = "com.example.myservice")
public class MyApplication {
  // ...
}

Problem: BeanCreationException

The BeanCreationException is thrown when a bean cannot be created during the application context initialization. This can happen when there is a problem with the configuration or dependencies of a bean.

Solution:

To resolve this issue, you need to identify the problem with the bean configuration or dependencies and fix it. This can be done by checking the error message and stack trace to see what is causing the exception.

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBean': Unsatisfied dependency expressed through field 'dependency1'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.Dependency1' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

In this example, the error message states that there is a missing bean of type ‘com.example.Dependency1’. To resolve this issue, you need to ensure that a bean of that type is defined and added to the application context.

Problem: Circular Dependency

A circular dependency occurs when two or more beans depend on each other, causing an infinite loop during the creation of the beans.

Solution:

To resolve this issue, you need to break the circular dependency by rethinking the design of the beans and their relationships. One common solution is to extract a common interface or abstract class that can be used by both beans instead of depending on each other directly.

public interface Dependency {
  // ...
}

@Service
public class Dependency1 implements Dependency {
  // ...
}

@Service
public class Dependency2 implements Dependency {
  // ...
}

@Service
public class MyBean {
  @Autowired
  private Dependency dependency;
  // ...
}

In this example, both Dependency1 and Dependency2 implement the Dependency interface, and MyBean depends on the interface instead of the concrete implementation. This breaks the circular dependency and allows the beans to be created correctly.

A brief introduction to Java Spring Cloud

Java Spring Cloud is a set of libraries and tools that are built on top of the Spring framework to provide a comprehensive platform for developing microservices-based applications. It enables developers to build and deploy scalable, highly available, and resilient cloud-based applications using the familiar and powerful Spring programming model.

Spring Cloud provides several key features for building cloud-based applications, including service discovery, configuration management, routing, load balancing, circuit breaking, security, and monitoring. With Spring Cloud, developers can easily develop and deploy microservices that can run on any cloud platform, including public cloud platforms like Amazon Web Services (AWS) and Microsoft Azure, and private cloud platforms like OpenStack and VMware. This makes it an ideal platform for building cloud-native applications that can take advantage of the benefits of cloud computing, such as scalability, reliability, and cost-effectiveness.

Most popular use cases for Java Spring Cloud

  1. Microservice Architecture: Java Spring Cloud can be used to build and deploy microservice-based applications. It provides a comprehensive set of libraries and tools for building scalable, highly available, and resilient cloud-based applications using the familiar and powerful Spring programming model.
  2. Service Discovery and Routing: Java Spring Cloud provides integrated support for service discovery and routing, making it easy to build and deploy microservices that can discover and route to each other automatically. The following code block demonstrates how to use Spring Cloud to register a service and discover it using Eureka:
@SpringBootApplication
@EnableEurekaClient
public class MyService {
  // ...
}

@RestController
public class MyController {
  @Autowired
  private DiscoveryClient discoveryClient;

  @GetMapping("/services")
  public List<String> services() {
    return discoveryClient.getServices();
  }
}
  1. Configuration Management: Java Spring Cloud provides centralized configuration management, making it easy to manage configuration data for multiple microservices in a consistent and scalable manner. The following code block demonstrates how to use Spring Cloud to manage configuration data using a Git repository:
@Value("${my.property}")
private String myProperty;

@ConfigurationProperties("my")
public class MyProperties {
  private String property;

  public String getProperty() {
    return property;
  }

  public void setProperty(String property) {
    this.property = property;
  }
}
spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/my/config-repo
          clone-on-start: true
  application:
    name: my-service
Share

It’s Really not that Complicated.

You can actually understand what’s going on inside your live applications.

Try Lightrun’s Playground

Lets Talk!

Looking for more information about Lightrun and debugging?
We’d love to hear from you!
Drop us a line and we’ll get back to you shortly.

By submitting this form, I agree to Lightrun’s Privacy Policy and Terms of Use.