Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: - spring

Caused by: org.springframework.beans.factory.CannotLoadBeanClassException:
Cannot find class
[org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]
for bean with name 'sessionFactory' defined in ServletContext resource >
[/WEB-INF/cardreaderapp-servlet.xml];
nested exception is java.lang.ClassNotFoundException:
org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean

i changed
org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
by
org.springframework.orm.hibernate4.LocalSessionFactoryBean
Because in Hibernate4 AnnotationSessionFactoryBean is replaced by LocalSessionFactoryBean
replaced
<bean class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFacoryBean" id="sessionFactory">
by
<bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" id="sessionFactory">
Thats fix the issue

From the error log it is clear that jvm can't find the class
org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
Make sure the dependent jar is there in your project. Other wise if you are using maven make sure the corresponding dependency(spring-orm) are added in the pom.xml file.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>

Related

JNDI lookup failure

i would be grateful if someone can help me rectify the issue in my code. Not sure where I'm going wrong.
Currently my persistence.xml contains
<property name="hibernate.transaction.manager_lookup_class" value="#####.hibernate.JbossTSTransactionManagerLookup"/>
<property name="hibernate.current_session_context_class" value="jta"/>
along with
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="####"/>
<property name="jpaDialect" ref="jpaDialect"/>
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:comp/env/TransactionManager"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
Context initialization failed : org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [###XMLConfig.xml]: Invocation of init method failed; nested exception is org.springframework.transaction.TransactionSystemException: JTA TransactionManager is not available at JNDI location [java:comp/env/TransactionManager]; nested exception is org.springframework.jndi.TypeMismatchNamingException: Object of type [class com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple] available at JNDI location [java:comp/env/TransactionManager] is not assignable to [javax.transaction.TransactionManager]
Caused by: org.springframework.transaction.TransactionSystemException: JTA TransactionManager is not available at JNDI location [java:comp/env/TransactionManager]; nested exception is org.springframework.jndi.TypeMismatchNamingException: Object of type [class com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple] available at JNDI location [java:comp/env/TransactionManager] is not assignable to [javax.transaction.TransactionManager]
at org.springframework.transaction.jta.JtaTransactionManager.lookupTransactionManager(JtaTransactionManager.java:598)
Caused by: org.springframework.jndi.TypeMismatchNamingException: Object of type [class com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple] available at JNDI location [java:comp/env/TransactionManager] is not assignable to [javax.transaction.TransactionManager] at org.springframework.jndi.JndiTemplate.lookup()
at org.springframework.transaction.jta.JtaTransactionManager.lookupTransactionManager()
Looks like there is some issue with the classpath of your project. Check if there are two versions of the same dependency in your project. In my case I had multiple versions of the jboss-transaction jar in the classpath, keeping just one version of it fixed the issue for me. Check if there is any transitive dependency which is causing this issue which you can exclude in your maven pom.

java.lang.NoClassDefFoundError: org/apache/cxf/jaxrs/model/doc/DocumentationProvider

I am trying to integrate swagger. I am following steps as given here. application context and pom.xml is configured same.
when restarting tomcat getting this error.
2018-04-30 14:01:33 ERROR ContextLoader:351 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productAPIServer': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/cxf/jaxrs/model/doc/DocumentationProvider
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
I have included
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description-swagger</artifactId>
<version>3.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description</artifactId>
<version>3.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.1.7</version>
</dependency>
Changes in context xml file:
<bean id="jacksonJsonProviderFasterxml" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
<bean id="swagger2Feature" class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
<property name="basePath" value="/staticdata-web-service"/>
<property name="license" value=""/>
<property name="licenseUrl" value=""/>
<property name="title" value="Static data web service"/>
</bean>
Added feature
<jaxrs:features>
<ref bean="swagger2Feature" />
</jaxrs:features>
You have a version mismatch. When you search on Maven for that class, you'll find that the package of the DocumentationProvider has changed from version 3.0.x to 3.1.x
org/apache/cxf/jaxrs/model/doc/DocumentationProvider
to
org/apache/cxf/jaxrs/model/wadl/DocumentationProvider
It's hard to tell where the mismatch is located without having insight into your entire build and package dependencies. But you may want to run
mvn dependency:tree -Dverbose
in your project folder to see which package versions come into question for raising your ClassNotFoundException.
use below dependency in your maven project to solve your issue,
<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-rs-json-basic -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-json-basic</artifactId>
<version>3.4.3</version>
<scope>provided</scope>
</dependency>

Spring transaction configuration in xml

I am trying to configure Spring transaction in my project. I have this configuration in my applicationContext.xml:
<bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect"
factory-method="aspectOf">
<property name="transactionManager" ref="transactionManager" />
</bean>
POM.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.2 RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.2 RELEASE</version>
</dependency>
On running the application, I encountered the following error:
WARNING: Exception encountered during context initialization - cancelling
refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.transaction.aspectj.AnnotationTransactionAspect#0'
defined in ServletContext resource
[/WEB-INF/spring/application-context.xml]: Bean instantiation via
factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.transaction.aspectj.AnnotationTransactionAspect]:
Factory method 'aspectOf' threw exception; nested exception is
org.aspectj.lang.NoAspectBoundException: Exception while initializing
org_springframework_transaction_aspectj_AnnotationTransactionAspect:
java.lang.NoSuchMethodError:
org.springframework.transaction.annotation.AnnotationTransactionAttributeSource.(Z)V
Suggest solution for the above exception.

getting error java.lang.NoClassDefFoundError: org/hibernate/validator/resourceloading/ResourceBundleLocator

I have a spring project in which i am using a validator like the following:
<beans:bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application"
p:fallbackToSystemLocale="false" />
<beans:bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<beans:property name="validationMessageSource" ref="messageSource" />
</beans:bean>
<annotation-driven validator="validator" />
<resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**" />
When i run the project i get the following BeanCreationException:
org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'validator' defined in ServletContext resource [/WEB-INF/spring/appServlet
/servlet-context.xml]: Error setting property values; nested exception is
org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'validationMessageSource' threw exception; nested exception is
java.lang.NoClassDefFoundError: org/hibernate/validator/resourceloading/ResourceBundleLocator
Here is my snippet of POM:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
<!-- Hibernate entity manager with JPA 2 support. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.0.Beta2</version>
</dependency>
<!-- Hibernate’s implementation of JSR-303. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<!-- The JSR-303 Bean Validation API library. -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
Why i am getting this error?
Thanks
Your dependencies are OK. Based on the provided information the error should not appear.
So I suggest you to check your IDE and whether the hibernate-validator dependency is really on classpath. If you are using Eclipse with M2E, try to update your project:
Project (right click on project) > Maven > Update Project....
This might be a broken backwards compatibility issue: https://jira.springsource.org/browse/SPR-10466
I had a similar problem using hibernate 5.2.10.Final and hibernate-validator 6.0.2.Final (that package version doesn't seem to be in sync with the others). Turns out, hibernate-validator's groupId was changed from org.hibernate to org.hibernate.validator. Once I made that change, the error went away, however I am using Dropwizard and noticed that there may be a version conflict somewhere, so that's something to keep an eye on.
I also had this exact same problem, tried all sorts of combinations of JAR versions, different bean definitions, even customised class implementations. Turns out, I just had to clean the project and restart Eclipse. Problem solved, and lesson learnt!
Check your dependency
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.8.Final</version>
</dependency>
Is must be at the same version of your other Hibernate dependencies.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Just use following dependency, it will fix your issue as this dependency provides basic validation from get go similar to hibernate.

Missing Spring AOP libraries in STS

I'm getting my feet wet with Spring. I downloaded STS and I'm following basic examples from Spring in Action Second Edition. I'm stuck when trying to implement basic AOP and I guess I'm just missing some specific libraries in my project.
I say so because annotations like #Aspect are not recognized in my classes like also <aop:config> in my xml.
This are my Maven Dependencies:
junit-4.7.jar
spring-test-3.0.2.RELEASE.jar
spring-context-3.0.2.RELEASE.jar
spring-aop-3.0.2.RELEASE.jar
aopalliance-1.0.jar
spring-beans-3.0.2.RELEASE.jar
spring-core-3.0.2.RELEASE.jar
commons-logging-1.1.1.jar
spring-expression-3.0.2.RELEASE.jar
spring-asm-3.0.2.RELEASE.jar
log4j-1.2.14.jar
Please let me know what libraries I'm missing and where to find them.
Thank you!
EDIT:
The following:
<bean id="performancePointcut"
class="org.springframework.aop.aspectj.AspectJExpressionPointcut" >
<property name="expression" value="execution(* Performer+.perform(..))" />
</bean>
throws the following exception:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'performancePointcut' defined in file [C:\Users\Prova\Documents\STS\SpringIdol3\src\main\resources\META-INF\spring\spring-idol.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
DONE!
This aspectj-annotation-tutorial did the job with steps 1, 2, and 3.
It's been a fun Friday night....
Put these two dependencies in your pom.xml:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
you may add maven dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>

Resources