Spring transaction configuration in xml - spring

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.

Related

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>

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

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>

Unable to create transactionManager (JTA) bean using Spring 2.5.6 on JBOSS EAP 6.3

I'm getting this error:
Error creating bean with name 'wsJtaTm' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class
[org.springframework.transaction.jta.JotmFactoryBean]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: stub class initialization failed
I'm using the following piece of code to create txnmanager bean for Jboss
Datasource and JNDI correctly loading and configured.
applicationcontext.xml
<bean id="wsJtaTm" class="org.springframework.transaction.jta.JotmFactoryBean" />
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="wsJtaTm" />
</bean>
What is wrong with my code?

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>

replaced-method question in spring 3

Excuse me. I'm a beginner of spring. Now, there's some question in it.
I'm reading Spring in action and try the code in MyEclipse. But when I try the code of replaced-method, there's a error.
<bean id="harry" class="com.springinaction.sprintidol.Magician">
<property name="magicBox" ref="magicBox" />
<property name="magicWords" value="Bippity boppity boo" />
</bean>
<bean id="magicBox" class="com.springinaction.sprintidol.MagicBoxImpl">
<replaced-method name="getContents" replacer="tigerReplacer" />
</bean>
<bean id="tigerReplacer" class="com.springinaction.sprintidol.TigerReplacer" />
This is the applicationContext.xml. And the exception as followed:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stevie' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter
All of the code come from the book. Why do I get the exception? And how to solve?
Thanks.
I found the reason. Because I didn't include the Spring 3.0 Persistence Core Libraries.Thanks all the same.

Resources