###前提・実現したいこと
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.

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。