Results 1 to 3 of 3

Thread: Testing Load-time woven domain objects with Maven Surefire

Threaded View

  1. #1
    Join Date
    Dec 2009
    Posts
    5

    Default Testing Load-time woven domain objects with Maven Surefire

    Dear All,

    I have a rather frustrating problem with running Spring integration tests with maven surefire plugin, using the TestContexts framework. The problem is typical based on the google results: I've tried to inject repositories into domain object by using LTW. It all works nicely when running the application, but the DAO is not injected when I try to run the integration tests. I've carefully followed the instructions to configure the surefire plugin, but the LTW feature still doesn't work.

    Here is my domain object:

    Code:
    @Entity
    @Table(name = "JOB_USER")
    @Configurable("user")
    public class User extends BaseEntity {
    
    	private static final long serialVersionUID = -6863852659859379841L;
    
    	@Transient
    	private transient UserDao userDao;
    
    	@Required
    	public void setUserDao(final UserDao userDao) {
    		this.userDao = userDao;
    	}
    
            [...]
    }
    and my Spring config:

    Code:
          
            <context:load-time-weaver/>
    	<context:spring-configured/>
    	<context:annotation-config/>	
    
    	<bean
    		id="userDao"
    		class="hu.jobportal.domain.user.dao.jpa.JpaUserDao"/>
    		
    	<bean
    		id="user"
    		class="hu.jobportal.domain.user.model.User"
    		scope="prototype">
    		
    		<property name="userDao" ref="userDao"/>
    		
    	</bean>
    Maven surefire plugin is configured like this:

    Code:
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <forkMode>once</forkMode>
                <argLine>
                -javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar
                </argLine>
                <useSystemClassLoader>true</useSystemClassLoader>
            </configuration>
    </plugin>
    The aop.xml is this:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <aspectj>
    	<weaver options="-verbose -debug -showWeaveInfo">
    		<include within="hu.jobportal..*"/>
    	</weaver>
    </aspectj>
    I'm using 3.0.0.RC3 version, but the same applies to 2.5.6. In the logs I can see that the AspectJ weaver is loaded and it prints a lot of debug messages about not weaving and weaving objects, but my User object is not there.

    The annoying thing is that it works perfectly when I bootstrap the ApplicationContext from a main method and instantiate a User object with new.

    Thanks in advance,
    Mark
    Last edited by nihilist; Dec 14th, 2009 at 11:39 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •