我是IntelliJ新手,並使用2016.2版本。以前我使用Eclipse。我正在嘗試建立一個簡單的Maven Spring測試項目,但我無法弄清楚什麼是錯的。IntelliJ IDEA 16向類路徑添加maven依賴關係
注:我知道異常是什麼意思,我知道使用Eclipse
注2解決方案:我試圖在一個乾淨的理念安裝
按我的理解,想法將包括Maven依賴自動(糾正我,如果我錯了)
編輯1:解決方案
- 項目 - >右鍵 - >添加框架支持 - >檢查春/ Spring MVC的
- 添加
<packaging>war</packaging>
- 重新導入Maven依賴
我試圖做
- 重新導入maven依賴關係
- 的IntelliJ關閉並刪除所有* .iml文件和所有.idea文件夾
異常
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>sample2</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sample2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
SAMPLE2-servlet.xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.test"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
p om.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sa</groupId>
<artifactId>sample2</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<spring.version>3.2.17.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
謝謝,這幫助我解決了紅色下劃線的其他依賴關係。 –
很高興解決了問題,請將答案標記爲已接受! – VinayVeluri
顯然我忘了將「 war 」添加到pom.xml文件中,甚至在我添加它後沒有正確導入。謝謝。 –