如何使用Maven管理項目?Maven管理項目實例
最近的練手項目使用的是 Maven 在管理項目,在使用 Maven 管理項目時,三層的開發(fā)時分模塊開發(fā)的,parent-dao-service-web,所有的spring+struts + Hibernate的依賴都是加在 parent 上,dao-service-web都是作為子模塊,在模塊之間的關(guān)系處理的時候出現(xiàn)了幾個問題:
junit測試包的傳遞依賴失效了
多個配置文件的讀取問題
我在 parent 工程沒有添加 Junit 的依賴,在編寫 dao 模塊是添加了 Junit 的 jar 包,理所當(dāng)然的在 scope 中寫了 test 范圍,但是在 service 模塊中進(jìn)行 Junit 測試時,顯示沒有依賴上 Junit 包,那是為什么呢?百度了才想通,原來是 service 依賴的 dao 模塊的 install 之后的 jar 包,當(dāng) dao 模塊 install 時,scope 為 test 的 Junit包當(dāng)然沒有被發(fā)布出來,service中也就不能傳遞依賴到 Junit了,這樣的解決辦法只能在 service 中添加 Junit 包的依賴。
因為采取的是模塊式的開發(fā),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()); } }
以上這篇如何使用Maven管理項目?Maven管理項目實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
idea中使用maven?archetype新建項目時卡住問題解決方案
這篇文章主要介紹了idea中使用maven?archetype新建項目時卡住,解決本問題的方法,就是在maven的runner加上參數(shù)-DarchetypeCatalog=local就可以了,不需要下載xml文件再放到指定目錄,需要的朋友可以參考下2023-08-08springboot X-Accel-Redirect 大文件下載實現(xiàn)
本文主要介紹了springboot X-Accel-Redirect 大文件下載實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06