質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

1回答

13435閲覧

SpringFrameworkのAutowiredのエラーについて

misaka

総合スコア31

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2017/07/24 03:04

編集2017/07/24 06:49
コード ```@Autowiredを使うことが出来ません。 すべてのクラスの同じpackageに入れて@Autowiredを使用しても下記のエラー文が出力されてプログラムが実行できません。 @ComponentScanを使用しても変わりません。 エラーが起こっている部分のプログラム文は下記の文です。 ```java @Service @Transactional public class CustomerService { @Autowired CustomerRepository customerRepository; public List<Customer> findAll(){ System.out.println("サービスfindAll()"); return customerRepository.findAllOrderByName(); } }
2017-07-24 11:29:21.356 WARN 5956 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerService': Unsatisfied dependency expressed through field 'customerRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'soturon.CustomerRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 2017-07-24 11:29:21.358 INFO 5956 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2017-07-24 11:29:21.382 INFO 5956 --- [ main] utoConfigurationReportLoggingInitializer : Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2017-07-24 11:29:21.457 ERROR 5956 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Field customerRepository in soturon.CustomerService required a bean of type 'soturon.CustomerRepository' that could not be found. Action: Consider defining a bean of type 'soturon.CustomerRepository' in your configuration.

申し訳ありません。以下CustomerRepositoryクラスになります。

java

1package soturon; 2 3import java.util.List; 4 5import org.springframework.data.jpa.repository.JpaRepository; 6import org.springframework.data.jpa.repository.Query; 7 8public interface CustomerRepository extends JpaRepository<Customer, Integer> { 9 10 @Query("SELECT * FROM customer") 11 List<Customer> findAllOrderByName(); 12 13 14 15}

以下、動作確認で作ったソースです。

java

1@Controller 2public class MemoController { 3 4 @Autowired 5 CustomerService cumser; 6 7 @RequestMapping("/") 8 public String memo(){ 9 cumser.aaa(); 10 return "MemoView"; 11 } 12 13 14@Service 15@Transactional 16public class CustomerService{ 17 //ためし 18 public void aaa(){ 19 20 System.out.println("できたー"); 21 } 22}```

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Tomohiro12

2017/07/24 03:21

CustomerRepositoryクラスのソースを追記していただけますか
guest

回答1

0

ベストアンサー

Repositoryに問題なさそうです
@EnableJpaRepositories("パッケージ")をどこかで有効にしてますか?

投稿2017/07/24 06:11

Tomohiro12

総合スコア112

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

misaka

2017/07/24 06:24

確認しましたが書いてありませんでした。
Tomohiro12

2017/07/24 06:28

@SpringBootApplicationが付与されたクラスに付与して動作を確認してみてください
misaka

2017/07/24 06:51

付与したところエラーが発生し動作しなくなってしまいました。 上記にサンプルプログラムを記述しました。 このプログラムだとAutowiredが動作しているものと思われますが。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問