2017-08-27 14 views
2

私はSpringを初めて使用しています。アクセスするデータ付きMySQLチュートリアルhereを参照してください。私は、Eclipseを使用している、と私はプロジェクトのために、すべてのコードをダウンロードして、春のブートアプリケーションとしてプロジェクトを実行すると、私はエラーを取得する:春MySQLでデータにアクセスできない


アプリケーションが


の起動に失敗しました

説明:

hello.MainControllerのフィールドuserRepositoryには、 'hello.UserRepository'タイプのBeanが見つかりませんでした。

処置:

はあなたの構成内の型 'hello.UserRepository' のBeanを定義することを検討してください。

これもまたチュートリアルのコードです。誰が何が起こっているか考えている?

ありがとうございます!

完全な実行ログ

. ____   _   __ _ _ 
 
/\\/___'_ __ _ _(_)_ __ __ _ \ \ \ \ 
 
(()\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 
 
\\/ ___)| |_)| | | | | || (_| | )))) 
 
    ' |____| .__|_| |_|_| |_\__, |//// 
 
=========|_|==============|___/=/_/_/_/ 
 
:: Spring Boot ::  (v1.5.6.RELEASE) 
 

 
2017-08-26 21:58:28.365 INFO 2308 --- [   main] hello.Application      : Starting Application on DESKTOP-F9F09K7 with PID 2308 (C:\Users\dylan\Desktop\gs-accessing-data-mysql-master\complete\target\classes started by dylan in C:\Users\dylan\Desktop\gs-accessing-data-mysql-master\complete) 
 
2017-08-26 21:58:28.367 INFO 2308 --- [   main] hello.Application      : No active profile set, falling back to default profiles: default 
 
2017-08-26 21:58:28.411 INFO 2308 --- [   main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]6b53e23f: startup date [Sat Aug 26 21:58:28 PDT 2017]; root of context hierarchy 
 
2017-08-26 21:58:29.454 INFO 2308 --- [   main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http) 
 
2017-08-26 21:58:29.465 INFO 2308 --- [   main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 
 
2017-08-26 21:58:29.466 INFO 2308 --- [   main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16 
 
2017-08-26 21:58:29.542 INFO 2308 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]  : Initializing Spring embedded WebApplicationContext 
 
2017-08-26 21:58:29.542 INFO 2308 --- [ost-startStop-1] o.s.web.context.ContextLoader   : Root WebApplicationContext: initialization completed in 1135 ms 
 
2017-08-26 21:58:29.655 INFO 2308 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 
 
2017-08-26 21:58:29.659 INFO 2308 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 
 
2017-08-26 21:58:29.667 INFO 2308 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 
 
2017-08-26 21:58:29.667 INFO 2308 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 
 
2017-08-26 21:58:29.667 INFO 2308 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 
 
2017-08-26 21:58:29.701 WARN 2308 --- [   main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainController': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'hello.UserRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
 
2017-08-26 21:58:29.703 INFO 2308 --- [   main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 
 
2017-08-26 21:58:29.721 INFO 2308 --- [   main] utoConfigurationReportLoggingInitializer : 
 

 
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 
 
2017-08-26 21:58:29.804 ERROR 2308 --- [   main] o.s.b.d.LoggingFailureAnalysisReporter : 
 

 
*************************** 
 
APPLICATION FAILED TO START 
 
*************************** 
 

 
Description: 
 

 
Field userRepository in hello.MainController required a bean of type 'hello.UserRepository' that could not be found. 
 

 

 
Action: 
 

 
Consider defining a bean of type 'hello.UserRepository' in your configuration.

答えて

0

はあなたがタイプUserRepositoryでリポジトリを登録していますか? @リポジトリアノテーションを使用してリポジトリに署名するかどうかを確認します。 gitのgs-accessing-data-mysql-master

  • から

  • +0

    ありがとうございました!リポジトリアナウンスでリポジトリに署名する方法を変更する方法を知っていますか?@Repositoryをリポジトリ定義の上に置くと、リポジトリを型に解決できないというメッセージが表示されます。 –

    +0

    org.springframework.stereotypeパッケージのリポジトリインタフェースはありますか? https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/stereotype/Repository.html タイプがターゲットになる可能性があります。 – Elliott

    +0

    org.springframework.stereotypeまたはorg.springframework.data.repository.Repositoryのいずれかを使用してリポジトリ定義の上に@Repositoryを置くと、「リポジトリはアノテーション型ではありません」と言われます。 –

    0
    1. ダウンロードプロジェクトあなたのディスクにファイルを解凍し
    2. オープンのEclipse
    3. [ファイル]> [インポート]> [既存のMavenプロジェクト>次
    4. [参照]をクリックして、あるgs-accessing-data-mysql-masterフォルダを選択あなたのディスク上に次のようにしてください。
    5. pom.xmlとFinishの両方を選択してください。
    6. Open gs-mysql-dataプロジェクトこのように、Application.javaに
    7. 右クリックを輸入し、

    CrudRepositoryからUserRepositoryインターフェイスが延びていることを確認したJavaアプリケーションやSpringブートアプリケーションとして実行されています:

    package hello; 
    
    import org.springframework.data.repository.CrudRepository; 
    
    import hello.User; 
    
    // This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository 
    // CRUD refers Create, Read, Update, Delete 
    
    public interface UserRepository extends CrudRepository<User, Long> { 
    
    } 
    
    +0

    完了。私はまだ同じエラーが発生します。 –

    +0

    'gs-mysql-data'プロジェクトに変更がないと仮定します。これを試してみてください: 'gs-mysql-data'プロジェクト> Maven> Update Project –

    +0

    を右クリックしてください。同じエラー。 –

    1

    私がすることができました私のMavenキャッシュをクリアしてこの問題を解決してください。

    C:\ Users \ユーザー名\ .m2

    フォルダ、その後、クリーンインストールをやって、私は手動で私を削除することによってこれをしませんでした。何が問題なのか、それがどのように発展したのか、それを修正するために何が変わったのかわからないことがあります。しかし、物事は再び働いているようです。

    誰もが助けてくれてありがとう!

    +0

    非常に良い情報 –

    関連する問題