maven 常見錯誤

1.使用maven,創建項目,之後出現錯誤,顯示如下

java.lang.ClassNotFoundException: org.springframework.expression.ParserContext

解決方法:添加節點如下

<!-- https://mvnrepository.com/artifact/org.springframework/spring-expression -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    <version>5.0.8.RELEASE</version>
</dependency>

####################################################################

2.junit使用的時候和hamcrest-all一起,pom.xml中添加的節點如下

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
   
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->
<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-all</artifactId>
    <version>1.3</version>
    
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>5.0.9.RELEASE</version>
 </dependency>

有的節點下會有<scope> 標籤。要去掉 

1. @RunWith(SpringJUnit4ClassRunner.class) 
表示這是一個Spring的測試類

2. @ContextConfiguration("classpath:applicationContext.xml")
定位Spring的配置文件

3. @Autowired
給這個測試類裝配Category對象

4. @Test
測試邏輯,打印c對象的名稱


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章