我爲我的應用程序使用Roo和編譯時編織。一個袋鼠已生成的類是我UserIntegrationTest
:爲什麼我的切入點不建議在另一個方面聲明的方法?
@RooIntegrationTest(entity = User.class)
@WebAppConfiguration
@ActiveProfiles("test")
@DirtiesContext
@RequiredUserDetails(roles=Role.ROOT)
public class UserIntegrationTest {
@Test
public void myTestMethod(){
}
}
大部分的代碼都是在袋鼠產生ITD:
privileged aspect UserIntegrationTest_Roo_IntegrationTest {
declare @type: UserIntegrationTest: @RunWith(SpringJUnit4ClassRunner.class);
declare @type: UserIntegrationTest: @ContextConfiguration(locations = "classpath*:/META-INF/spring/applicationContext*.xml");
declare @type: UserIntegrationTest: @Transactional;
@Autowired
UserDataOnDemand UserIntegrationTest.dod;
@Autowired
UserService UserIntegrationTest.userService;
@Autowired
UserRepository UserIntegrationTest.userRepository;
@Test
public void UserIntegrationTest.testCountAllUsers() {
Assert.assertNotNull("Data on demand for 'User' failed to initialize correctly", dod.getRandomUser());
long count = userService.countAllUsers();
Assert.assertTrue("Counter for 'User' incorrectly reported there were no entries", count > 0);
}
...
...
...
}
我寫我自己的方式來處理我的@RequiredUserDetails
註釋。我的切入點指定了用@RequiredUserDetails
註解的類中的任何@Test
方法。儘管切入點對於主類中聲明的任何方法都可以正常工作(即:MyTestMethod()
),但它不會採用ITD中的任何方法。
@Aspect
public class RequiredUserDetailsAspect {
/**
* Defines any public <code>@Test</code> method
*/
@Pointcut("execution(public * *(..)) && @annotation(org.junit.Test)")
public void testMethod() {};
/**
* Anything with the {@link RequiredUserDetails} annotation on the method
*/
@Pointcut("@annotation(RequiredUserDetails)")
public void annotatedMethod(){};
/**
* Anything with the {@link RequiredUserDetails} annotation on the class
*/
@Pointcut("@within(RequiredUserDetails)")
public void annotatedClass(){};
@Before("testMethod() && (annotatedClass() || annotatedMethod())")
public void authenticateUser(JoinPoint jp){
// check for any class annotations
}
}
我會預料到,鑑於Roo ITD正在CTW,我的方面也適用於這些方法。我假定我的方面是在Roo方面編織的,因此Roo的ITD並不是我班的一部分。
是否有辦法確保Roo的ITD在我自己的方面之前編織或確保我的切入點適用於Roo ITD?
我嘗試添加@DeclarePrecedence
的方面的頂部,但是要麼沒有工作,我希望,或者我把它錯誤地定義,因爲它已經沒有區別。
@Aspect
@DeclarePrecedence("**.*Roo*, RequiredUserDetailsAspect")
public class RequiredUserDetailsAspect {
...
...
}