Declarative transaction management with Spring 2 and AspectJ
I'm playing with Hibernate, Spring 2 and AOP. Configuring this stuff were some kind of challenge for me. But now it woks. I faced wery interesting exeption during configuration. Since I'm using Maven 2, Spring + Hibernate dependency looks like this:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-hibernate3</artifactId>
<version>2.0.5</version>
</dependency>
Exception is looks like this :
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:Strange ! I have appropriate configuration for namespaces at my applicationContext.xml :
Line 63 in XML document from class path resource [applicationContext.xml] is invalid;
nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c:
The matching wildcard is strict, but no declaration can be found for element 'aop:config'.
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c:
The matching wildcard is strict, but no declaration can be found for element 'aop:config'.
<beans xmlns="http://www.springframework.org/schema/beans"Config :
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<aop:config>
<aop:advisor id="serviceTxAdvisor"
pointcut="execution(public *
com.company.service.impl.ServiceImpl.*(..))"
advice-ref="txAdviceForService" />
</aop:config>
<tx:advice id="txAdviceForService"
transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
Solution suggested at Spring forum doesn't work for me. I had no success with Xerces. So, I decided to digg a little more. As a result I've found two missing dependencies that should make me happy:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>2.0.5</version>
</dependency>
Weird exception vanished. I'm very happy now.
BTW, even you use
