How do I get my Maven plugin to execute as part of running a JUnit test in Eclipse?

157 views Asked by At

I’m using Eclipse Mars, JUnit 4.11, Hibernate 4.3.6.Final, and JPA 2.1. I have imported a Maven project into Eclipse using the m2e plugin. I have this plugin in my pom.xml file …

                    <plugin>
                            <groupId>org.bsc.maven</groupId>
                            <artifactId>maven-processor-plugin</artifactId>
                            <version>2.1.1</version>
                            <executions>
                                    <execution>
                                            <id>process</id>
                                            <goals>
                                                    <goal>process</goal>
                                            </goals>
                                            <phase>generate-sources</phase>
                                            <configuration>
                                                    <processors>
                                                            <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                                                    </processors>
                                            </configuration>
                                    </execution>
                            </executions>
                            <dependencies>
                                    <dependency>
                                            <groupId>org.hibernate</groupId>
                                            <artifactId>hibernate-jpamodelgen</artifactId>
                                            <version>4.3.10.Final</version>
                                    </dependency>
                            </dependencies>
                    </plugin>

If I have a domain class, “User”, the above plugin will generate a class “User_”, for use with JPA CriteriaBuilder queries. Unfortunately, when I run my tests in Eclipse, I get errors like below (these do not happen when I run “mvn clean test -Dtest=MyTest” at the command line).

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyProjectOrganizationController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.mainco.subco.myproject.service.MyProjectOrganizationService org.mainco.subco.myproject.controller.MyProjectOrganizationController.m_MyProjectOrgSvc; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyProjectOrgService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.mainco.subco.myproject.repo.MyProjectOrganizationDao org.mainco.subco.myproject.service.MyProjectOrganizationServiceImpl.m_MyProjectOrganizationDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyProjectOrganizationDaoImpl' defined in file [/Users/davea/Documents/sb_workspace/core/target/classes/org/mainco/subco/myproject/repo/MyProjectOrganizationDaoImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.mainco.subco.myproject.repo.MyProjectOrganizationDaoImpl]: Constructor threw exception; nested exception is java.lang.Error: Unresolved compilation problems: 
    The import org.mainco.subco.myproject.domain.MyProjectOrganization_ cannot be resolved
    The import org.mainco.subco.organization.domain.Organization_ cannot be resolved
    The import org.mainco.subco.url.domain.Url_ cannot be resolved
    MyProjectOrganization_ cannot be resolved to a variable
    MyProjectOrganization_ cannot be resolved to a variable
    MyProjectOrganization_ cannot be resolved to a variable
    MyProjectOrganization_ cannot be resolved to a variable
    Organization_ cannot be resolved to a variable
    Url_ cannot be resolved to a variable
    Organization_ cannot be resolved to a variable
    MyProjectOrganization_ cannot be resolved to a variable
    MyProjectOrganization_ cannot be resolved to a variable

    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:290)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1148)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:636)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:102)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:246)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
    ... 25 more

The classes the error is complaining about are generated with the plugin I listed above, but for some reason, when I run JUnit tests (by right clicking on the class name in the Eclipse editor and selecting “Run As” -> “JUnit Test”), the plugin isn’t getting called. How do I force my plugin to be run as part of executing a JUnit test in Eclipse?

0

There are 0 answers