Spring compilation issues

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Spring compilation issues

Alexander Fedulov
Hi,

I want to compile some tests written in groovy using groovy-eclipse-plugin. Say I have a simple empty test (using Spock framework):

package com.***.spec

import org.springframework.context.ApplicationContext
import org.springframework.context.support.ClassPathXmlApplicationContext

import spock.lang.Specification

@ContextConfiguration(locations = "classpath:applicationContextTest.xml")
class EmptyTest extends Specification {

        private final static Logger LOG = Logger.getLogger(EmptyTest.class)
       
        def "Empty test"(){
                given:
                        def a = 'abc'
                expect:
                        a.reverse() == 'cba'
        }
       
}

I reduced my Spring application context to this:

<?xml version="1.0" encoding="UTF-8"?>
<beans ...>

  <aop:config>
                <aop:aspect id="serviceExceptionAspect" ref="logex">
                        <aop:after-throwing method="log" throwing="ex" pointcut="execution(* com.****.service..*.*(..))"/>
                </aop:aspect>
        </aop:config> -->
       
         <jpa:repositories base-package="com.sabienzia.idp.repositories" /> 

          <bean id="logex" class="com.sabienzia.idp.aspect.ExceptionLoggingAspect"/>

</beans>


Whenever either aop:config or jpa:repositories or both are not commented out, I get the following exception:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested
exception is java.lang.IllegalStateException: No persistence exception translators found in bean factory. Cannot perform exception translation.
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:142)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.<init>(PersistenceExceptionTranslationInterceptor.java:79)
        at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor.<init>(PersistenceExceptionTranslationAdvisor.java:71)
        at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:85)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1508)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1476)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
        at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:741)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
        at com.***.EmptyTest.$spock_initializeFields(EmptyTest.groovy:13)


The same problem occurs in normal Java JUnit tests, if they are compiled using groovy-eclipse-compiler.

My pom.xml configuration looks like this:

          .....
         <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-all</artifactId>
                        <version>2.0.6</version>
                </dependency>
          .....

                    <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <version>3.1</version>
                                <configuration>
                                        <compilerId>groovy-eclipse-compiler</compilerId>
                                        <source>1.6</source>
                                        <target>1.6</target>
                                        <verbose>true</verbose>
                                </configuration>
                                <dependencies>
                                        <dependency>
                                                <groupId>org.codehaus.groovy</groupId>
                                                <artifactId>groovy-eclipse-compiler</artifactId>
                                                <version>2.8.0-01</version>
                                        </dependency>
                                        <dependency>
                                                <groupId>org.codehaus.groovy</groupId>
                                                <artifactId>groovy-eclipse-batch</artifactId>
                                                <version>2.0.7-03</version>
                                        </dependency>
                                </dependencies>
                        </plugin>

                <plugin>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-compiler</artifactId>
                    <version>2.8.0-01</version>
                    <extensions>true</extensions>
                 </plugin>


Does it have to do anything with some Spring AOP or reflection internals? Is there any option that has to be explicitly set in the configuration to enable Spring support?

Kind Regards
Alexander Fedulov