2017-08-06 5 views
2

私は最初のアプリケーションとしてSpring Frameworkを学び始めました。定義済みのBeanカウントを取得しようとしましたが、実行できません。 こんにちは、春5のアプリケーション・コンテキスト

import org.springframework.context.ApplicationContext; 
import org.springframework.context.annotation.AnnotationConfigApplicationContext; 


public class runDemo { 
    public static void main(String[] args) { 
     ApplicationContext context = new AnnotationConfigApplicationContext(); 
     System.out.println(context.getBeanDefinitionCount()); 
    } 
} 

と私のGradleファイル

buildscript { 
ext { 
    springBootVersion = '1.5.6.RELEASE' 
} 
repositories { 
    mavenCentral() 
} 
dependencies { 
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
} 
} 

apply plugin: 'java' 
apply plugin: 'eclipse' 
apply plugin: 'org.springframework.boot' 

version = '0.0.1-SNAPSHOT' 
sourceCompatibility = 1.8 

repositories { 
mavenCentral() 
} 


dependencies { 

compile('org.springframework.boot:spring-boot-starter') 
testCompile('org.springframework.boot:spring-boot-starter-test') 
} 

を、私が実行したときに、これは:

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext 
at java.lang.Class.forName0(Native Method) 
at java.lang.Class.forName(Class.java:264) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123) 
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext ... 

私は外部ライブラリでの春のコンテキストとスプリングコアがロードされています。

編集:私はのIntelliJアイデア2017.2にアップグレードし、それはまだ同じエラーに

+0

compile('org.springframework.boot:spring-boot-starter') 

を置き換え? – Oleg

+0

私はrunDemoクラスを実行します...私はビデオチュートリアルとして行ったが、今何が間違っているのか分からないのですか? – Mehrad

+2

IDEを使用していますか?これは、初めてのアプリの場合は、おそらくより簡単な何かで始まる? SpringがないHello Worldのように。 – Oleg

答えて

0

を与える私はあなたがそれを実行するにはどうすればよい

compile('org.springframework.boot:spring-boot-starter-web') 
関連する問題