前提・実現したいこと
SpringでDOMAを使いたいのですが、SampleRepositoryが見つからないとエラーを吐かれてしまいます。
SampleApplicationの階層を移動させてみたりしているのですが、状況が変わりませんでした。
呼び出している階層も問題なさそうなのですが、どこが間違っているかわからない状況です。
発生している問題・エラーメッセージ
*************************** APPLICATION FAILED TO START *************************** Description: Field sampleRepository in com.example.sample.domain.service.SampleService required a bean of type 'com.example.sample.domain.repository.SampleRepository' that could not be found. Action: Consider defining a bean of type 'com.example.sample.domain.repository.SampleRepository' in your configuration.
該当のソースコード
package com.example.sample.domain.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.example.sample.domain.model.SampleEntity; //ここが呼ばれてくれない import com.example.sample.domain.repository.SampleRepository; @Service public class SampleService { @Autowired SampleRepository sampleRepository; public List<SampleEntity> getSample () { return sampleRepository.selectAll(); } }
階層
@SampleApplication
package com.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication(scanBasePackages={"com.example.sample"}) @RestController public class SampleApplication { @RequestMapping("/") String hello() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(SampleApplication.class, args); } }
@SampleController
package com.example.sample.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.example.sample.domain.model.SampleEntity; import com.example.sample.domain.service.SampleService; @RestController public class SampleController { @Autowired SampleService sampleService; @RequestMapping(value = "/sample", method = RequestMethod.GET) public List<SampleEntity> getSample () { return sampleService.getSample(); } }
@SampleEntity
package com.example.sample.domain.model; import org.seasar.doma.Entity; import org.seasar.doma.Id; import org.seasar.doma.Table; @Entity @Table(name = "sample") public class SampleEntity { @Id private int id; // private String name; // //~ getter, setter 省略 ~ }
@SampleRepository
package com.example.sample.domain.repository; import java.util.List; import org.seasar.doma.Dao; import org.seasar.doma.Select; import org.seasar.doma.boot.ConfigAutowireable; import com.example.sample.domain.model.SampleEntity; @ConfigAutowireable @Dao public interface SampleRepository { @Select List<SampleEntity> selectAll(); }
@SampleService
package com.example.sample.domain.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.example.sample.domain.model.SampleEntity; //ここが呼ばれてくれない import com.example.sample.domain.repository.SampleRepository; @Service public class SampleService { @Autowired SampleRepository sampleRepository; public List<SampleEntity> getSample () { return sampleRepository.selectAll(); } }
補足情報
Eclipse
SpringToolSuite4
DOMA2
PostgreSQL
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。