IncompatibleClassChangeError - Uprade to Spring 4.1.7 - spring

We have a tomcat application that has a spring container running on 3.0.0. Upgraded to spring 4.1.7, and modified certain classes appropriately. One of the beans that we modified used CronTriggerBean. That was changed to use CronTriggerFactoryBean, and also upgraded to org.quartz-scheduler to 2.2.1. When deploying and starting tomcat, encountered the following exception.
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'appsecScheduler' defined in class path resource [application-
context.xml]: Initialization of bean failed; nested exception is
java.lang.IncompatibleClassChangeError: Implementing class at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean
(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean
Attached a debugger and found the offending class to be CronTriggerFactoryBean. But this issue happens only when deploying in a Windows environment. WHen the same war is deployed in Ubuntu, the application starts without any errors. For the record, I did a dependency:tree, dependency:build-classpath and ensured that 3.0.0 spring was not in use. The CronTriggerFactoryBean is part of spring-context-support.
Any suggestions on how to debug further or determine which jar is being used?

Related

Spring boot testing : NoClassDefFound exception

I'm using the latest version of Spring boot and an old test fails.
I'm having
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class
Caused by: java.lang.NoClassDefFoundError: MyClass
My config is
spring boot 2.7.2
gradle 7.5
a structure using idiomatic gradle (multiproject and composite build)
The subproject failing is the spring-boot-application. The class not found exists inside the src/main/java
The test failing is under src/test/java, annotated with
#SpringJUnitConfig(classes = ApplicationServiceAspectTestConfigSuccessListener.class) because it is using #Inject fields.
I understand it is not perfect (unit testing depending on injection ; prefer integration test)
When I debug this test, the classloader tries to use a JarLoader and searches inside the spring-boot-application-default.jar. The jar structure is BOOT-INF / META-INF / org... The class not found is inside the BOOT-INF/classes/org/xxxx. The jar loader failed :/
My question is : why searching inside the jar and not the build/classes/org/xxx ? and why is the JarLoader not finding the class ?
Update 1
I think I have a lead. I created a gradle precompiles quality plugins which uses java-text-fixtures. When enable the java-text-fixtures produces two jars and the problem comes from here.
I don't really understand why for the moment (why 2 jars and not only the text-fixtures one).
Update 2
Ok seems I ran across https://github.com/gradle/gradle/issues/11696

Trouble deploying Grails 5.1.1 app on tomcat

I have created a Grails 5.1.1 app from the command line with "grails create-app".
It runs fine, from the command line "grails run-app", and I can build a war file which can be run from the command line with "java -jar app-0.1.war".
I then attempted to follow the instructions for deploying in a container (Tomcat 8 and Tomcat 9 in my case) by adding the context-path and changing the build dependency. The documentation says to change "org.springframework.boot:spring-boot-starter-tomcat" to provided in build.gradle. "provided" is not a valid option as far as I can tell. I've tried both providedCompile and providedRuntime with the same result as below.
When I deploy the resulting app-0.1-plain.war I get one of two errors:
The bean 'characterEncodingFilter' could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/web/servl
et/HttpEncodingAutoConfiguration.class] and overriding is disabled.
with the suggested remedy of adding: spring.main.allow-bean-definition-overriding=true
results in a circular bean reference for hibernateDatastore.
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'hibernateDatastore': Requested bean is currently in creation: Is there an unresolvable circular reference?
I'm using openjdk version "1.8.0_292" of Java, Gradle 7.2 and I tried deploying on apache-tomcat-8.5.73 and apache-tomcat-9.0.56.
Any ideas about what might be wrong with my set up that prevents the deploy war from running?
Edit: This seems to be a manifestation:
https://github.com/grails/grails-core/issues/12288 and/or
https://github.com/grails/grails-core/issues/12278
Though the work around suggested did not work for me I do not experience the same problem with 5.0.3 as suggested in 12278.

deploying jsf jpa web application in weblogic 12.1.1

i am developping a web application using Maven , JSF 2.2 ,JSTL 1.2.1 , JPA 2.1 , Spring 4.2.9, Hibernate-jpa-api-2.1
i can deploy my application in Tomcat and run it without problems , but i want deploy in weblogic 12.1.1 as well but i got some problems starting my app server :
nested exception is java.lang.NoSuchMethodError : javax.persistance.Table.indexes()[Ljavax/persistence/Index;
....
org.springframework.beans.factory.BeanCreationException : Error creatin bean with name 'myEmf' defined in class path resource [jpaConfig.xml]
....
Error javax.entreprise.resource.webcontainer.jsf.application
i have created a weblogic.xml in my deployed war like this :
<prefer-application-packages>
<package-name>javax.faces.*</package-name>
<package-name>com.sun.faces.*</package-name>
<package-name>com.bea.faces.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>javax.faces.*</resource-name>
<resource-name>com.sun.faces.*</resource-name>
<resource-name>com.bea.faces.*</resource-name>
<resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
</prefer-application-resources>
The error message "java.lang.NoSuchMethodError" indicates a library collision with the JPA 2.0 Library of Weblogic. Since you are packing your own library for that, try adding "javax.persistence.*" to the weblogic.xml
Option 2: Add the JPA 2.1 Support to weblogic classpath
In your domain/bin/setDomainEnv (.cmd for windows, .sh for unix) add a PRE_CLASSPATH Variable. On a windows System this would look like this:
set PRE_CLASSPATH=C:/weblogic_12130/oracle_common/modules/javax.‌​persistence_2.1.jar;‌​C:/weblogic_12130/wl‌​server/modules/com.o‌​racle.weblogic.jpa21‌​support_1.0.0.0_2-1.‌​jar

CDI Beans module deployment failed: couldn't start owb context

I have a Maven project. The build runs properly including tests. But when I run the tests only using Eclipse Luna, then the tests fail:
javax.enterprise.event.ObserverException: Caught Exception while handling event object with type : org.apache.webbeans.portable.events.discovery.AfterBeanDiscoveryImpl
...
Caused by: java.lang.AbstractMethodError: org.apache.webbeans.container.InjectableBeanManager.getInjectionTargetFactory(Ljavax/enterprise/inject/spi/AnnotatedType;)Ljavax/enterprise/inject/spi/InjectionTargetFactory;
at com.sun.faces.util.cdi11.CDIUtilImpl.createHelperBean(CDIUtilImpl.java:76)
at com.sun.faces.flow.FlowCDIExtension.afterBeanDiscovery(FlowCDIExtension.java:120)
... 60 more
INFO - Undeploying app: .../classpath.ear
org.apache.openejb.OpenEJBException: Creating application failed: /home/schnikow/projects/barbuchon2/BarbuchonKernel-2.0r0b-SNAPSHOT/classpath.ear: couldn't start owb context
(full stack trace is too long, I can provide it if needed)
I've add the needed JVM argument (-javaagent:/usr/devel/apache-tomee-webprofile-1.7.1/lib/openejb-javaagent.jar) in the launch configuration. I may miss something trivial, but I haven't any idea, what.
I use Eclipse Luna and Tomee embedded EJB container running on Java 8 virtual machine.
it seems you use mojarra, is it a CDI 1.0 compatible version or 1.1 (only TomEE 2 will be CDI 1.1/1.2 compatible)

Grails 1.2.1 with Spring 3.0.0 dependency problem under Jetty

Just moved to Grails 1.2.1 (used 1.1.1 before). Changed application.properties, ran grails upgrade, fixed BuildConfig and Bootstrap - everything works just fine from grails console.
However, getting a problem when deploy packaged war under jetty 6.1.22:
1581 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is java.lang.NoSuchMethodError: org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.setParameterNameDiscoverer(Lorg/springframework/core/ParameterNameDiscoverer;)V
My project is built with maven2. I researched the war dependencies and see that both spring 2.5.6 and 3.0.0.RELEASE are used there.
I then tried to suppress use of spring 2.5.6 and got a problem with Acegi plugin (using version 0.5.1):
2010-03-10 21:06:56.440:WARN::Nested in org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.setId(Ljava/lang/String;)V
Any help would be greatly appreciated.
The problem is caused by the fact that in new version of Spring
ConfigurableWebApplicationContext is located in spring-web.jar, but the interface it inherits ConfigurableApplicationContext, which contains setId(String) method is in located in spring-context.jar.
If you have a library which has been compiled against older version of spring-context it will fail with NoMethodFound exception.
The solution is to locate and recompile that library against latest Spring version.
If you are using Spring version below 3.0 you could try to put full Spring bundle Jar instead of separate packages.

Resources