Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. package pl.springBootStarter.app;
  2.  
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5.  
  6. @SpringBootApplication
  7. public class CourseApiDataApplication
  8. {
  9. public static void main(String args[])
  10. {
  11. SpringApplication.run(CourseApiDataApplication.class,args);
  12. }
  13. }
  14.  
  15. package pl.springBootStarter.app.topic;
  16.  
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19.  
  20. import java.util.ArrayList;
  21. import java.util.Arrays;
  22. import java.util.List;
  23.  
  24. @Service
  25. public class TopicService
  26. {
  27. @Autowired
  28. private TopicRepository topicRepository;
  29.  
  30. private List<Topic> topics = new ArrayList<>(Arrays.asList(
  31. new Topic("spring","spring framework", "spring framework dectription"),
  32. new Topic("sprin","spring framework", "spring framework dectription"),
  33. new Topic("spri","spring framework", "spring framework dectription")));
  34.  
  35. public List<Topic> getAllTopics()
  36. {
  37. // return topics;
  38. List<Topic> t = new ArrayList<Topic>();
  39. topicRepository.findAll().forEach(t::add);
  40. return t;
  41. }
  42.  
  43. public Topic getTopic (String id)
  44. {
  45. return topics.stream().filter( t -> t.getId().equals(id)).findFirst().get();
  46. }
  47.  
  48. public void addTopic(Topic topic) {
  49. topicRepository.save(topic);
  50. }
  51.  
  52. public void updateTopic(Topic topic, String id)
  53. {
  54. topics.set(topics.indexOf(topics.stream().filter(t-> t.getId().equals(id)).findFirst().get()), topic);
  55. }
  56.  
  57. public void deleteTopic(String id)
  58. {
  59. topics.remove(topics.stream().filter(t -> t.getId().equals(id)).findFirst().get());
  60. }
  61. }
  62.  
  63. package pl.springBootStarter.app.topic;
  64.  
  65. import org.springframework.data.repository.CrudRepository;
  66.  
  67. public interface TopicRepository extends CrudRepository<Topic,String>
  68. {
  69.  
  70. }
  71.  
  72. Error starting ApplicationContext. To display the conditions report re- run your application with 'debug' enabled.
  73. 2019-05-01 10:33:52.206 ERROR 6972 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
  74.  
  75. ***************************
  76. APPLICATION FAILED TO START
  77. ***************************
  78.  
  79. Description:
  80.  
  81. Field topicRepository in pl.springBootStarter.app.topic.TopicService required a bean of type 'pl.springBootStarter.app.topic.TopicRepository' that could not be found.
  82.  
  83. The injection point has the following annotations:
  84. - @org.springframework.beans.factory.annotation.Autowired(required=true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement