2016-09-07 2 views
2

IntelliJ를 처음 사용하고 2016.2 버전을 사용합니다. 이전에는 Eclipse를 사용하고있었습니다. 나는 간단한 maven 스프링 테스트 프로젝트를 만들려고 노력하고 있지만 무엇이 잘못되었는지를 알 수는 없다.IntelliJ IDEA 16 클래스 경로에 종속성 추가

참고 : 나는 예외가 무엇을 의미하는지 알고, 내가 이클립스

주 2 사용하여 솔루션을 알고 : 나는 깨끗한 아이디어 설치 나의 이해 당으로

에 노력을, 아이디어는 포함됩니다 받는다는 종속성은 자동으로 (내가 틀렸다면 정정 해줘)

편집 1 :솔루션

01 23,516,
  1. 프로젝트 -> 오른쪽 클릭 -> 추가 프레임 워크 지원 -> 봄/스프링 MVC는
  2. 내가

    을하려고 무엇 <packaging>war</packaging>
  3. 다시 가져 오기 받는다는 종속성

을 추가 확인

  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를 열 때 클릭합니다.

그렇지 않은 경우 Intellij의 오른쪽 창에서 Maven Projects을 클릭하고 refresh ->Generate sources and auto import 뒤에 버튼을 클릭하십시오. 그러면 프로세스가 다시 트리거됩니다.위에서 작동하지 않고 여전히 IDE에 문제가있는 경우

Maven-IntelliJ

File -> Invalidate Cache/Restart 옵션으로 이동합니다. 그러면 아래와 같이 프롬프트됩니다.

enter image description here

클릭 Invalidate and restart에,이 것 다시 인덱스 작업 공간에 대한 모든 종속성.

+1

감사합니다. 이것은 빨간색 밑줄이있는 다른 종속성을 해결하는 데 도움이되었습니다. –

+0

문제가 해결되었습니다. 답변을 수락 된 것으로 표시하십시오. – VinayVeluri

+0

분명히 " war"을 pom.xml 파일에 추가하는 것을 잊었습니다. 추가 한 후에도 제대로 가져 오지 않았습니다. 감사. –

1

이동> 파일 - 설정 -> 구축, 실행, 배포는 -> buildtools - 홈 디렉토리> 받는다는 받는다는 홈 디렉토리. 작동하지 않는 경우, 파일 -> 설정 -> 빌드, 실행, 배포 -> 빌드 도구 -> 빌드 -> 가져 오기 탭에서 maven 프로젝트를 자동으로 가져 오기를 선택하십시오.

+0

언급 한 설정은 기본적으로 이미 설정되어 있습니다. 내가 놓친 게 있니? –

0

다시 가져 오기를 강제 실행하려면 "보기"메뉴 (또는 기본적으로 도킹 된 화면의 오른쪽)에서 maven 프로젝트 도구 창을 열고 가장 왼쪽 아이콘 (화살표가있는 파란색 원 모양 그것).
이렇게하면 IntelliJ가 처음부터 pom을 구문 분석하고 누락 된 종속성을 가져와야합니다.
종종 자동 가져 오기가 예상대로 작동하지 않는 경우 다시 시작하고 캐시를 지우는 것보다 빠릅니다.