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

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

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

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

Spring Boot

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

Q&A

解決済

1回答

10264閲覧

spring boot+doma2のアプリケーション作成時のエラー

sakipon_1983

総合スコア15

Java

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

Spring Boot

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

0グッド

2クリップ

投稿2016/06/19 07:32

編集2016/06/19 07:51

###前提・実現したいこと

spring bootを使ったwebアプリケーションを構築しており、その中でDBとのやりとりにdoma2を
使用しようとしております。

下記のサイトを参考に簡単なWEBアプリケーションを作成してみましたが、エラーとなり
原因がわからないため、対処方法を教えてください。

<http://qiita.com/ARS_2000/items/4c680ec9b31725687e04>
<https://github.com/domaframework/doma-spring-boot/blob/master/README.md>

###発生している問題・エラーメッセージ


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoApplication': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.example.ReservationDao com.example.DemoApplication.reservationDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.ReservationDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]

###該当のソースコード
[DemoApplication]

package com.example; import java.util.Arrays; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @RestController public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Autowired ReservationDao reservationDao; // Insert data at initailizing phase using ReservationDao#insert @Bean CommandLineRunner runner() { return args -> Arrays.asList("spring", "spring boot", "spring cloud", "doma").forEach(s -> { Reservation r = new Reservation(); r.name = s; reservationDao.insert(r); }); } @RequestMapping(path = "/") List<Reservation> all() { return reservationDao.selectAll(); } }

[Reservation]

package com.example; import org.seasar.doma.Entity; import org.seasar.doma.GeneratedValue; import org.seasar.doma.GenerationType; import org.seasar.doma.Id; @Entity public class Reservation { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Integer id; public String name; }

[ReservationDao]

package com.example; import java.util.List; import org.seasar.doma.Dao; import org.seasar.doma.Insert; import org.seasar.doma.Select; import org.seasar.doma.boot.ConfigAutowireable; import org.springframework.transaction.annotation.Transactional; @ConfigAutowireable @Dao public interface ReservationDao { @Select List<Reservation> selectAll(); @Insert @Transactional int insert(Reservation reservation); }

[selectAll.sql]

SELECT id, name FROM reservation ORDER BY name ASC

[schema.sql]

CREATE TABLE reservation ( id IDENTITY, NAME VARCHAR(50) );

###試したこと

参考にしたhttps://github.com/domaframework/doma-spring-boot/blob/master/README.mdを確認すると、
ReservationDaoImplというファイルがコンパイルされるとありますが、実際に自分の環境ではclassが作成していませんでした。
※他のクラスファイルはtarget配下に出力していたので、パスまちがいはないともうのですが。。。

Build again, then compilation will succeed and you can see ReservationDaoImpl is generated under target and compiled.

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

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

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

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

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

guest

回答1

0

自己解決

構成を下記の通りに変更することで、コンパイルできた。

【BEFORE】
├─src
│ ├─main
│ │ ├─java
│ │ │ └─com
│ │ │ └─example
│ │ │ │ Application.java
│ │ │ │
│ │ │ ├─controller
│ │ │ │ CustomerController.java
│ │ │ │
│ │ │ ├─model
│ │ │ │ Customer.java
│ │ │ │
│ │ │ ├─repository
│ │ │ │ CustomerRepository.java
│ │ │ │
│ │ │ └─service
│ │ │ CustomerService.java

【AFTER】
├─src
│ ├─main
│ │ ├─java
│ │ │ └─com
│ │ │ └─example
│ │ │ │ Application.java
│ │ │ │
│ │ │ ├─controller
│ │ │ │ CustomerController.java
│ │ │ │
│ │ │ ├─domain
│ │ │ │---model
│ │ │ │ Customer.java
│ │ │ │
│ │ │ ├─repository
│ │ │ │ CustomerRepository.java
│ │ │ │
│ │ │ └─service
│ │ │ CustomerService.java

投稿2016/06/21 14:15

sakipon_1983

総合スコア15

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問