Consider defining a bean of type のエラーについて

前提

「後悔しないためのSpring Boot 入門書:Spring 解体新書」という書籍でSpring Bootの学習を行なっている中で、題名のエラーが発生しました。

実現したいこと

springbootを起動できるようにし、一覧画面を表示できるようにしたいです。
このエラーは基本的にアノテーションの漏れがないかくらいしか可能性がないのかなと感じますが、どこか不自然に感じる箇所などはありますでしょうか?
よろしくお願いいたします。

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

*************************** APPLICATION FAILED TO START *************************** Description: Field mapper in com.example.domain.user.service.impl.UserServiceImpl required a bean of type 'com.example.repository.UserMapper' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'com.example.repository.UserMapper' in your configuration.

該当のソースコード

UserMapper.java

1package com.example.repository; 2 3import org.apache.ibatis.annotations.Mapper; 4 5import com.example.domain.user.model.MUser; 6 7@Mapper 8public interface UserMapper { 9 10 //ユーザー登録 11 public int insertOne(MUser user); 12}

UserServiceImpl.java

1package com.example.domain.user.service.impl; 2 3import org.springframework.beans.factory.annotation.Autowired; 4import org.springframework.stereotype.Service; 5 6import com.example.domain.user.model.MUser; 7import com.example.domain.user.service.UserService; 8import com.example.repository.UserMapper; 9 10@Service 11public class UserServiceImpl implements UserService { 12 13 @Autowired 14 private UserMapper mapper; 15 16 //ユーザー登録 17 @Override 18 public void signup(MUser user) { 19 user.setDepartmentId(1);//部署 20 user.setRole("ROLE_GENERAL");//ロール 21 mapper.insertOne(user); 22 } 23} 24

UserService.java

1package com.example.domain.user.service; 2 3import com.example.domain.user.model.MUser; 4 5public interface UserService { 6 7 //ユーザー登録 8 public void signup(MUser user); 9 10}

JavaConfig.java

1package com.example.config; 2 3import org.modelmapper.ModelMapper; 4import org.springframework.context.annotation.Bean; 5import org.springframework.context.annotation.Configuration; 6 7@Configuration 8public class JavaConfig { 9 10 @Bean 11 public ModelMapper modelMapper() { 12 return new ModelMapper(); 13 } 14}

試したこと

@beanなどのアノテーションの書き漏れなどがないかを確認しましたが問題ありませんでした。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

コメントを投稿

0 コメント