使用 Maven 管理項目,使用maven管理項目

來源:互聯網
上載者:User

使用 Maven 管理項目,使用maven管理項目

 

最近的練手項目使用的是 Maven 在管理項目,在使用 Maven 管理項目時,三層的開發時分模組開發的,parent-dao-service-web,所有的spring+struts + Hibernate的依賴都是加在 parent 上,dao-service-web都是作為子模組,在模組之間的關係處理的時候出現了幾個問題:

 

       我在 parent 工程沒有添加 Junit 的依賴,在編寫 dao 模組是添加了 Junit 的 jar 包,理所當然的在 scope 中寫了 test 範圍,但是在 service 模組中進行  Junit 測試時,顯示沒有依賴上 Junit 包,那是為什麼呢?百度了才想通,原來是 service 依賴的 dao 模組的 install 之後的 jar 包,當 dao 模組 install 時,scope 為 test 的 Junit包當然沒有被發布出來,service中也就不能傳遞依賴到 Junit了,這樣的解決辦法只能在 service 中添加 Junit 包的依賴。

      因為採取的是模組式的開發,spring的設定檔就被分布在各個模組中了,在測試專案時需要讀取多個模組中的 spring 設定檔時,使用到了之前沒有使用到的一個註解:

   @ContextConfiguration(locations={"classpath*:applicationContext-*.xml"}) 這個註解中的*號萬用字元表示會載入本模組和依賴的jar包中的類路徑下的applicationContext-開頭的設定檔(只有spring設定檔才會這樣命名)

//@ContextConfiguration(locations={"classpath*:applicationContext-*.xml"})@ContextConfiguration(locations={"classpath:applicationContext-dao.xml","classpath:applicationContext-service.xml"})@RunWith(SpringJUnit4ClassRunner.class)public class CustomerServiceImplTest {    @Autowired    private CustomerService customerService;        @Test    public void test() {        Customer customer = customerService.findById(1L);        System.out.println("********************"+customer.getCustName());    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.