31 12月 2008

Eclipse Templates

routine 的工作到處都是,Coding中也常有重覆的工作,利用IDE可以有效減少這些問題。 例如經常宣告slf4j/commons Logger,或是新增UnitTest TestCase後要加上annotations,Eclipse中的Templates可以快速的完成。 在Eeclipse->Java->Editor->Templates中加入像下列兩項templates
${:import(org.slf4j.Logger, org.slf4j.LoggerFactory)}
private static final Logger logger = LoggerFactory.getLogger(${primary_type_name}${cursor}.class);
${:import(org.junit.runner.RunWith, org.springframework.test.context.ContextConfiguration, org.springframework.test.context.junit4.SpringJUnit4ClassRunner)}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:application*.xml" })
這樣只要經由code assist就能快速將這些宣告完成。

沒有留言: