开发者

Spring @Configurable does not work if new method with domain classes as parameter was added to unit test

开发者 https://www.devze.com 2023-03-10 20:20 出处:网络
I need to inject dependencies into my domain classes, so I use @Configurable as follows: @Configurable(preConstruction=true,dependencyCheck=true)

I need to inject dependencies into my domain classes, so I use @Configurable as follows:

@Configurable(preConstruction=true,dependencyCheck=true)
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name="TBL_COMPANY")
class Company
{
   @Id
   private long id;

   @Autowired
   private transient IIdentityQueryService identityQueryService;

   Company()
   {
     Assert.notNull(identityQueryService, "IIdentityQueryService was not injected");
   }
}

My aop.xml:

<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
    <weaver options="-verbose">
        <include within="com.xl.nrs.identity.*"/>
        <exclude within="*..*CGLIB*"/>
        <exclude within="*..*javassist*"/>
        <exclude within="*..*DTO*"/>
        <exclude within="*..*Service*"/>
        <exclude within="*..*Test*"/>
    </weaver>
</aspectj>

I include the following in my application context file:

...
<context:spring-configured/>
<context:load-time-weaver/>
...

JVM parameter:

-javaagent:../NRS-SharedLibs/lib/org.springframework.instrument-3.0.5.RELEASE.jar

Lastly, my simplified unit test:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/mycontext.xml"})
public class TestCompany
{
   @Test
   public void testCreateCompany() throws Exception
   {
      Company company = new Company();
   }
}

Everything went fine until I add new method to my unit test with the domain class as one of its parameters:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/mycontext.xml"})
public class TestCompany
{
   @Test
   public void testCreateCompany() throws Exception
   {
      Company company = new Company();
   }

   //New method that makes @Configurable no开发者_Go百科t working
   private void someNewMethod(Company company)
   {
      ...
   }
}

This time the dependency wouldn't get injected, no errors, no nothing.

If the parameter of the new method was not the domain classes everything went fine again.

It's so strange because I only added method to the unit test class, not the domain class or anywhere else.

Has anyone experienced the same problem ?

Any help would be greatly appreciated.

Thanks & Regards,

Setya

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号