[AspectJ] Extension and Implementation
declare parents: EmpDao extends GenericDao<Emp, EmpParams>;
declare parents: EmpDaoImpl extends HibernateGenericDao<Emp, EmpParams>;
declare @type: EmpDaoImpl: @org.springframework.stereotype.Repository;
EmpDao 클래스가 GenericDao 클래스를 상속 받도록 설정.
EmpDaoImpl 클래스가 HibernateGenericDao 클래스를 상속 받도록 설정.
EmpDaoImpl 클래스에 @Repository 애노테이션 추가.
문법이 복잡해 보였는데 막상 사용해보니 간단 간단 하네요.
public interface EmpDao {
}
public class EmpDaoImpl implements EmpDao {
}
이런 기초적인 코드만 존재하지만..
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/applicationContext.xml", "/applicationContext-datasource.xml"})
@Transactional
public class EmpDaoImplTest {
@Autowired
EmpDaoImpl daoImpl;
@Test
public void daoInterface() throws Exception {
assertNotNull(daoImpl);
daoImpl = new EmpDaoImpl();
GenericDao<Emp, EmpParams> gdao = daoImpl;
HibernateGenericDao<Emp, EmpParams> hgdao = daoImpl;
}
@Test
public void crud() throws Exception {
Emp emp = new Emp();
daoImpl.add(emp);
daoImpl.flush();
assertEquals(1, daoImpl.getAll().size());
}
}
이런 테스트를 돌릴 수 있다는거...