Announcement Announcement Module
Collapse
No announcement yet.
Testing Load-time woven domain objects with Maven Surefire Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 12:39 PM.

  • #2
    ShadowingClassLoader

    Could it be somehow connected to the ShadowingClassLoader black-magic? I'm out of ideas, so please help me.

    Comment


    • #3
      Jpa

      As I have suspected, the problem only occurs when I use JPA. I refactored my project to use only Hibernate with its plain Session API and then it worked as expected in the test cases.

      Anyone has any ideas how to revert back to JPA. I'm comfortable with plain Hibernate, but anyways I'd like to use JPA if possible.

      Thanks in advance.

      Ps.: Am I just talking to myself?

      Comment

      Working...
      X