Using Camel 2.1 with Grails 1.2.1 - Classloading problem - spring

I'm trying to define a Camel context in my Grails application.
resource.groovy:
xmlns camel: 'http://camel.apache.org/schema/spring'
camel {
camelContext(id:'camelContext') {
}
}
Results in a stacktrace containing:
2010-02-03 13:24:42,209 [main] ERROR spring.GrailsRuntimeConfigurator - [RuntimeConfiguration] Unable to load beans from resources.groovy
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: org/apache/camel/spi/ManagementStrategy
The strange thing is that ManagementStrategy is in lib/camel-core-2.1.0.jar. I'm not that familiar with neither Spring nor Camel so any suggestions are welcome. Can this be a classloader issue?

Read the release notes for Apache Camel 2.1
http://camel.apache.org/camel-210-release.html
There is a section with new .jar dependencies.
You need commons-management .jar on the classpath.

Related

Exception in thread "main" java.lang.StackOverflowError at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)

I am working on a spring multi module project. I have upgraded spring version from 3.x to 5.3.17. After upgradation, while running project Iam getting following error:
Exception in thread "main" java.lang.StackOverflowError
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.apache.commons.logging.LogAdapter$Slf4jAdapter.createLocationAwareLog(LogAdapter.java:130)
at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:91)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
at org.slf4j.impl.JCLLoggerFactory.getLogger(JCLLoggerFactory.java:88)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.apache.commons.logging.LogAdapter$Slf4jAdapter.createLocationAwareLog(LogAdapter.java:130)
at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:91)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
at org.slf4j.impl.JCLLoggerFactory.getLogger(JCLLoggerFactory.java:88)
in build.gradle file:
compile(group: "org.springframework", name: "spring-core", version: "3.0.5.RELEASE").Here version changed to 5.3.17
similar things applied for spring-context,spring-web etc spring related dependencies in build.gradle
Your SLF4J uses JCL as backend and your JCL uses SLF4J as backend, hence the StackOverflow.
Newer versions of Spring have spring-jcl as transitive dependency and they redirect logging coded using Jakarta Commons Logging to SLF4J.
If moreover you have a slf4j-jcl binding on your classpath that performs the opposite redirect, you get a StackOverflowException.
Just remove slf4j-jcl from your dependencies and you should be fine.

Unable to make field static final java.lang.invoke.MethodHandles$Lookup java.lang.invoke.MethodHandles$Lookup.IMPL_LOOKUP

I have a Spring Feign client which is sending POJO object to remote endpoint using POST and my application start-up fails with below exceptions.
java.lang.reflect.InaccessibleObjectException: Unable to make field static final java.lang.invoke.MethodHandles$Lookup java.lang.invoke.MethodHandles$Lookup.IMPL_LOOKUP accessible: module java.base does not "opens java.lang.invoke" to unnamed module #420a85c4
Below the dependencies I am using in my application.
java version: 17
spring boot version: 2.5.3
spring boot cloud version: 2020.0.3
spring boot starter openfeign version: 2.2.8.RELEASE
As recommended in https://github.com/OpenFeign/feign/issues/935, I had tried
workaround solution: Adding this jvm option '--add-opens java.base/java.lang.invoke=ALL-
UNNAMED' worked.
Any other alternative suggestion other than jvm argument are most welcome.
Force OpenFeign version to at least 11.7, which has this issue solved.
If you are using Spring Dependency Management plugin, then you can do it like this (Gradle example):
dependencyManagement {
dependencies {
dependencySet(group: 'io.github.openfeign', version: '11.7') {
entry 'feign-core'
entry 'feign-jackson'
entry 'feign-slf4j'
entry 'feign-soap'
entry 'feign-jaxb'
}
}
}
For me it worked to add the following JVM Option:
--add-opens java.base/java.lang.invoke=ALL-UNNAMED
For JDK 9+, if you use the JVM options to fix the problem, add another = into the JVM options:
e.g.
--add-opens=java.base/java.lang.invoke=ALL-UNNAMED
I have same error when i declare default method (method with implementation) in interface class marked with #FeignClient. I just remove default method and the error has disappeared

Spring-boot BOM does not contain a dependency for tomcat-dbcp

Spring-boot BOM does not contain a dependency for tomcat-dbcp.
I have a Spring MVC project where I use a database connection pool for Hibernate ORM connections. This project is deployed in Tomcat. In my IntelliJ Idea development environment I use Tomcat embedded, by using the spring-boot-starter-tomcat. But the spring-boot-starter-tomcat does not define a dependency to tomcat-dbcp. Hence I decided to explicitly define a dependency to tomcat-dbcp in my build.gradle.kts file.
I had hoped that the Spring-boot BOM would have contained tomcat-dbcp, so that I would not need to specify it's version number and rely on the Spring Boot dependency management system to handle it's version number for me. But the Spring-boot BOM does not contain a dependency for tomcat-dbcp. Can Spring-Boot add it?
I came up with the following hack so as to not hard code the version number for tomcat-dbcp. Just added the following code to the build.gradle.kts file after dependencies section.
configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.apache.tomcat.embed" && requested.name == "tomcat-embed-core") {
dependencies {
providedRuntime("org.apache.tomcat", "tomcat-dbcp", requested.version) //to use tomcat connection pool in tomcat embedded mode.
}
}
}
}

Swagger UI with Java9 (spring boot 2.0)

I'm trying to make the swagger UI work with my service. I'm using spring boot 2.0 and Java 9. The following dependencies are added for swagger
compile('io.springfox:springfox-swagger2:2.8.0')
compile('io.springfox:springfox-swagger-ui:2.8.0')
The swagger is configured as it should
#Configuration
#EnableSwagger2
public class SwaggerConfig {
#Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Compiles well but when I starting up the application with the BootRun command it fails due:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xmlModelPlugin': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [springfox.documentation.schema.XmlModelPlugin] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#4f8e5cde]
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 25 common frames omitted
What could be the problem? Not compatible with Java9? Then can I make it work somehow?
Yes, that's incompatibility with java 9.
I think you have three options:
add explicit dependency to xml apis like compile('javax.xml.bind:jaxb-api:2.3.0')
update springfox version to 2.9.0
add --add-modules java.xml.bind to jvm startup params (this is more just a workaround instead of a fix, in comparison to other options, since this module will be removed in the later versions of java)
Further reading on Spring Boot and java 9: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-with-Java-9-and-above
I am not sure about this very specific error, but in general Swagger 2.9.x seems to have some incompatibility with SpringBoot 2.0.x
Some documented issues:
https://github.com/springfox/springfox/issues/1773 (main one)
https://github.com/springfox/springfox/issues/2501
There is a 3.0.0-SNAPSHOT version which might be more stable with this Spring Boot version.
version 2.9.0 could not be found in maven central. Available versions are 2.9.1 and 2.9.2
https://mvnrepository.com/artifact/io.springfox/springfox-swagger2
As suggested by #eis after upgrade from 2.8.0 to 2.9.2 fixed the issue for me

Log4j conflicts- container provided and project level

We got a couple of grails applications running, each with its own Log4j classes.
They need to be moved with a server that has log4j provided by Tomcat.
It it possible to get the grails applications to use the tomcat provided libraries?
Any help would be appreciated.
You can try excluding log4j from Grails depencies so that Tomcat provided log4j will be used:
grails.project.dependency.resolution = {
inherits("global") {
excludes "log4j"
}
}

Resources