I have a Spring Boot (2.2.6) project that has another starter as a dependency:
<dependency>
<groupId>com.companyX.teamY</groupId>
<artifactId>Z-starter</artifactId>
<version>0.0.1</version>
</dependency>
But I get a error java.lang.IllegalStateException: Failed to introspect Class because of missing
java.lang.ClassNotFoundException: springfox.documentation.spring.web.plugins.Docket
I don't find any springfox under project's external libraries dropdown (in IntelliJ) so I digged into the source of custom starter and found this:
#Bean
#ConditionalOnMissingBean(Docket.class)
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("A Sample Project")
.version("0.0.1")
.build())
.select()
.apis(basePackage("com.companyX"))
.build();
}
But the starter project does have
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
in its pom.xml. If I add above to my Spring Boot project the error goes away so I am not sure why IntelliJ or maven isn't able to resolve such dependency: Spring Boot APP -> Custom Starter -/> SpringFox. What am I missing here?
Versions:
Java SDK: 1.8.0_231
Maven: 3.6.2
SpringBoot: 2.2.6.RELEASE for both projects
I ran mvn clean install and did not see any errors. The error only appears for one of those contextloads test method.
EDIT:
After some digging, this looks to be an issue with transitive dependencies not being resolved, but then I followed the steps of running mvn install on both projects to no avail.
Related
I'm upgrading a set of legacy applications to Spring Boot 2.4.0, running on OpenJDK 8, deployed to Pivotal Cloud Foundry.
The app and all its unit tests ran perfectly under Spring 2.3.4-RELEASE before I started this upgrade.
There was work to be done right off the bat: Spring Boot 2.4.0 brings in JUnit 5.x, so I had to fix all the JUnit 4.x tests to use the new annotations and classes.
After fixing all the tests I tried to run in IntelliJ 2020.2. All the tests failed, for the same reason: java.lang.IllegalStateException: Failed to load ApplicationContext. The root of the stack trace gives this cause:
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
They removed a fundamental class from Spring Boot for the sake of Kubernetes, from the sound of it. I'm not sure I see why.
I did a Google search and found this explanation and fix.
I added spring.config.use-legacy-processing to my application.yml and a test application.properties file:
spring:
config:
use-legacy-processing: true
Still no joy - all the tests fail.
I'm confused by other links I've seen. Is this an issue with spring-cloud-dependencies? I'm reading that there might an issue with the Hoxton version. Do I need to add it to my app? It never needed this dependency before the upgrade:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR9</version>
<type>pom</type>
<scope>import</scope>
</dependency>
The problem is bigger than the tests. If I ignore them and try to run the app I still fail:
ERROR [main]: Application run failed |ApplicationName=Risk_Advisor | sourcedfrom=ERROR
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader#18b4aac2]
The root cause is the same:
java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
when ever you do upgrades on spring, pls always look at the spring / cloud compatibility matrix and then upgrades the versions for both spring and cloud accordingly:
Also, pls note that you may not have added spring cloud as direct dependency but it may be coming into your final jar as a transitive dependency so its always better to add below spring cloud dependency as direct dependency management in your pom to stay away from any conflicts:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
I got the same error when migrating to Spring Boot 2.4.4 which forced me to migrate to Spring Cloud 2020.0.1 as well. In my case, the error was due to Bootstrap, provided by spring-cloud-commons, not being any longer enabled by default. I had to re-enabled it by adding the following new starter in my build.gradle file as stated here:
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
You say your app doesn't use Spring Cloud, so I'm not sure why you ended up facing which seems to be the same issue. Hopefully this workaround might work for you and help out others using Spring Cloud.
To fix the failing JUnit 4 tests, I have just added it as a dependency:
testImplementation 'junit:junit:4.13'
I had the same error for JUnit 4 tests after migration my project to Spring Boot 2.5.6. Adding JUnit 4 dependencies did not fix this error as well as migration JUnit 4 tests to JUnit 5. My project does not define Spring Cloud dependencies in build.gradle so in order to find where those dependencies come from I simply ran gradle command:
gradle dependencyInsight --dependency org.springframework.cloud
and saw that spring cloud dependencies were pulled within one of the custom libraries. Upgrade spring cloud dependencies to a compatible version there and reimport custom library fixed the error.
I have created a project using Spring Initializr with Spring Boot V-2.0.3
I am using STS 3.9.4 on Ubuntu Machine.
I am getting these errors:
The import org.springframework.boot.autoconfigure.SpringBootApplication cannot be resolved
SpringBootApplication cannot be resolved to a type
I have already tried deleting the repository folder from .m2 folder and hitting the following commands
mvn clean dependency:tree
mvn clean compile
But still errors were not resolved than I added an Extra Dependency to the POM file
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-autoconfigure -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
I have updated the project by following the below steps after each step performed but still the error is not resolved.
STS Right click on project -> Maven -> Update Project
Go to STS Right click on project -> Maven -> Update Project.
Spring boot Cassandra starter 1.5.1 throws exceptions:
java.lang.ClassNotFoundException: com.google.common.util.concurrent.AsyncFunction
and
java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
when trying to create CassandraClusterFactoryBean object.
Is there a workaround for this?
A new Spring data - cassandra project from start.spring.io also throws a similar exception in its test run.
ClassNotFoundException means that those classes are not in your classpath, then you should add this dependency to your pom.xml
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.01</version>
</dependency>
If you are not using maven, just go to the this link and download the jar file and include that in your java classpath
Depending on how you are doing your project, this version of this dependency will change, just look for a compatible version for your spring-data version here
Update:
You should use guava 16.01 method, because in guava 19 method the method is not valid anymore as the API said
#Deprecated
#GwtIncompatible(value="TODO")
public static ListeningExecutorService sameThreadExecutor()
Deprecated. Use directExecutor() if you only require an Executor and newDirectExecutorService() if you need a ListeningExecutorService.
This method will be removed in August 2016.
According to the this in the compiled dependencies section, guava is 16.01
Can any one suggest how to resolve the ClassCastException while adding dependency jar in pom.xml?
I have created a new maven project having returning the object in runtime and then execute the ovverride method definition as based upon client request.
Ex: actionPerform(actionType) -- this method return the 'Object'
public static CommonActions action(ActionTypes actionType)
{
return (CommonActions)actionPerform(actionType);
}
Code is working fine and then successfully executing. There is no ClassCastExceptions while adding this jar into library tab on project properties using eclipse.
Getting ClassCastExceptions on above return statement while adding the below depenedency in pom.xml
<dependency>
<groupId>com.amadeus.selenium.merci</groupId>
<artifactId>appium-amadeus-utilities</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
I am using maven version 3.0.4
Please suggest how I resolve the ClassCastException at runtime while adding dependency jar in pom.xml.
I am working on a Grails project that needs to compile with both Grails and Maven. Everything worked great except for my GSON converter I added (using the grails-gson plugin). Now I get the following when I run mvn install.
unable to resolve class grails.plugin.gson.converters.GSON
Anyone know how to overcome this
Plugin has to be added as a dependency in pom.xml too
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>gson</artifactId>
<version>1.1.4</version>
<type>zip</type>
</dependency>
Mavenized grails project refer pom file for all dependencies (including plugin dependencies).