前提
ここに質問の内容を詳しく書いてください。
JavaのSpring Frameworkをつかって、
webアプリケーションを作成しています
実現したいこと
複数のBeanを登録したい
発生している問題・エラーメッセージ
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
該当のソースコード
Info.java
1package com.example.demo.entity; 2 3import org.springframework.beans.factory.annotation.Qualifier; 4import org.springframework.stereotype.Component; 5 6@Component(value="Info") 7public class Info implements Serializable{ 8 9 private static final long serialVersionUID = 1L; 10 11 private int examId; 12 13 private String examName; 14 15 private String examDate; 16 17 18 19 20 21 public int getExamId() { 22 return examId; 23 } 24 25 26 public void setExamId(int examId) { 27 this.examId = examId; 28 } 29 30 31 public void setExamName(String examName) { 32 this.examName = examName; 33 } 34 35 36 public void setExamDate(String examDate) { 37 this.examDate = examDate; 38 } 39 40 41 public String getExamName() { 42 return examName; 43 } 44 45 46 public String getExamDate() { 47 return examDate; 48 } 49 50 51}
User.java
1package com.example.demo.entity; 2 3import java.io.Serializable; 4 5import org.springframework.beans.factory.annotation.Qualifier; 6import org.springframework.stereotype.Component; 7 8 9@Component(value="User") 10public class User implements Serializable{ 11 12 private static final long serialVersionUID = 1L; 13 14 15 private int userId; 16 private int pass; 17 18 public int getUserId() { 19 return userId; 20 } 21 public void setUserId(int userId) { 22 this.userId = userId; 23 } 24 25 public int getPass() { 26 return pass; 27 } 28 public void setPass(int pass) { 29 this.pass = pass; 30 } 31 32 33 34 35 36} 37
ServiceExamInfoImpl.java
1package com.example.demo.service; 2 3import java.util.List; 4 5import org.springframework.beans.factory.annotation.Autowired; 6import org.springframework.beans.factory.annotation.Qualifier; 7import org.springframework.stereotype.Service; 8 9import com.example.demo.dao.ExamInfoDao; 10import com.example.demo.entity.Info; 11 12@Service 13public class ServiceExamInfoImpl implements TestService { 14 15 @Autowired 16 ExamInfoDao dao; 17 18 @Autowired 19 @Qualifier("Info") 20 Info info; 21 22 23 @Override 24 public List selectWhere(Object t) { 25 26 Info info = (Info)t; 27 28 List<Info> list = dao.selectWhere(info); 29 30 return list; 31 } 32}
ServiceUserImpl.java
1package com.example.demo.service; 2 3import java.util.List; 4 5import org.springframework.beans.factory.annotation.Autowired; 6import org.springframework.beans.factory.annotation.Qualifier; 7import org.springframework.stereotype.Service; 8 9import com.example.demo.dao.UserDao; 10import com.example.demo.entity.Info; 11import com.example.demo.entity.User; 12 13@Service 14public class ServiceUserImpl implements TestService { 15 16 @Autowired 17 UserDao dao; 18 19 @Autowired 20 @Qualifier("User") 21 User user; 22 23 24 @Override 25 public List selectWhere(Object t) { 26 27 User u = (User)t; 28 29 List<User> list = dao.selectWhere(u); 30 31 return list; 32 33 34 }
試したこと
複数のBeanがあることが問題だと思ったので、
@Qualifierを付与したのですが、エラーメッセージが取れませんでした
補足情報(FW/ツールのバージョンなど)
Spring boot
Gradle
を使ってます
あなたの回答
tips
プレビュー