2016-09-07 9 views
2

私はIntelliJを新しく使用し、2016.2バージョンを使用しています。以前はEclipseを使用していました。私は単純なmavenの春のテストプロジェクトを設定しようとしていますが、何が間違っているのか分かりません。IntelliJ IDEA 16クラスパスに依存関係を追加します

注:私は例外が何を意味するか知っている、と私はEclipseの

注2使用してソリューションを知っている:私はアイデアが含まれます、私の理解あたりとしてクリーンアイデアのインストール

にしようとしたをMavenの依存関係を自動的に(私が間違っているなら、私を修正)

編集1:ソリューション

  1. プロジェクト - >右クリック - > [Frameworkのサポートを追加 - >チェック春/ Spring MVCの
  2. は私が

    を実行しようとしました何<packaging>war</packaging>
  3. 再輸入Mavenの依存関係

を追加します

  1. 再インポート依存関係
  2. 閉じるの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> 

答えて

4

Auto Importがチェックインされた場合は、IntelliJのを開くと、アイデアはMavenの依存関係が含まれます自動的に (私が間違っているなら、私を修正)

はい、それはよう促しとするときをクリックします。

Intellijの右側のウィンドウでMaven Projectsをクリックし、refresh - >Generate sources and auto importの後にボタンをクリックしてください。これにより、プロセスが再度トリガーされます。

Maven-IntelliJ

上記動作しない、まだあなたはIDEに問題がある場合は、File -> Invalidate Cache/Restartオプションにアクセスしてください。それは以下のように促す。

enter image description here

クリックInvalidate and restartで、このう再インデックスワークスペースにすべての依存関係。

+1

ありがとう、これは私に赤い下線を持つ他の依存関係を解決するのに役立ちました。 –

+0

問題を解決してうれしいです、答えを受け入れたとマークしてください! – VinayVeluri

+0

明らかに、「 war」をpom.xmlファイルに追加するのを忘れていました。追加した後でも、正しくインポートされませんでした。ありがとう。 –

1

ゴー - >ビルド、実行、展開 - >ビルドツール - > mavenの Mavenのホームディレクトリホームディレクトリに。 それが動作しない場合は、File-> settings-> build、Execution、Deployment-> buildtools-> maven-> importingタブで、mavenプロジェクトを自動的にインポートします。私の理解あたりとして

+0

あなたが言及した設定は、デフォルトで既に設定されています。何か不足していますか? –

0

強制的に再インポートするには、「表示」メニュー(またはデフォルトでドッキングされている画面の右側)からmavenプロジェクトツールウィンドウを開き、最も左のアイコンを押します(矢印が付いた青い円のように見えます)それ)。
これはIntelliJにpomを最初から解析し、欠落している依存関係をインポートさせるはずです。
自動インポートが期待通りに機能しない場合は、再起動してキャッシュをクリアするよりも速くなることがよくあります。

関連する問題