Assert Null and Aspect

When apply the handy Assert.notNull, we should be aware that it might throw IllegalArgumentException.
@Aspect
@Component
public class ExceptionAspect {
	private final Logger log = LoggerFactory.getLogger(getClass());

	@AfterThrowing(throwing = "ex", pointcut = "within(com.xxx.broker..*)")
	public void catchIllegalArgumentException(Throwable ex) {
		log.error("IllegalArgumentException occurs! ", ex);
	}
}
Test:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:applicationContext.xml")
@ActiveProfiles("test")
public class ExceptionAspectTest {
	@Autowired
	private IBrokerService brokerService;
	
	@Test
	public void testInputNull(){
		brokerService.getAllHoldings(null);
	}
}
Service
@Override
	public Response getAllHoldings(Request request) {
		Assert.notNull(request);
		Response response = new Response();

		...
		return response;
	}
Application context:

POM.xml


			org.aspectj
			aspectjrt
			${aspectj.version}
		
		
			org.springframework
			spring-aop
			${springframework.version}
		
		
			org.aspectj
			aspectjweaver
			${aspectj.version}
		










你可能感兴趣的:(J2EE)