Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. <dependencies>
  2. <dependency>
  3. <groupId>com.h2database</groupId>
  4. <artifactId>h2</artifactId>
  5. <scope>runtime</scope>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.springframework.boot</groupId>
  9. <artifactId>spring-boot-starter-data-jpa</artifactId>
  10. </dependency>
  11. </dependencies>
  12.  
  13. <dependencyManagement>
  14. <dependencies>
  15. <dependency>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-dependencies</artifactId>
  18. <version>2.1.4.RELEASE</version>
  19. <type>pom</type>
  20. <scope>import</scope>
  21. </dependency>
  22. </dependencies>
  23. </dependencyManagement>
  24.  
  25. @Entity
  26. public class Person {
  27. @Id
  28. @GeneratedValue(strategy = GenerationType.IDENTITY)
  29. private Integer id;
  30.  
  31. @Column(name = "name")
  32. private String name;
  33.  
  34. @Column(name = "last_name")
  35. private String lastName;
  36.  
  37. @Column(name = "age")
  38. private Integer age;
  39.  
  40. @Column(name = "createdAt")
  41. @Temporal(TemporalType.TIMESTAMP)
  42. private Date createdAt;
  43. ...
  44. }
  45.  
  46. @Repository
  47. public interface PersonRepository extends CrudRepository<Person, Integer> {
  48.  
  49. }
  50.  
  51. @SpringBootApplication
  52. public class SpringDataApplication {
  53.  
  54. public static void main(String[] args) throws Exception {
  55. ConfigurableApplicationContext context = SpringApplication.run(SpringDataApplication.class, args);
  56. PersonRepository personRepository = context.getBean(PersonRepository.class);
  57. Person p1 = new Person("Juan", "Camaney", 55);
  58. Person p2 = new Person("Arturo", "Lopez", 33);
  59. Person p3 = new Person("Pancho", "Coscorin", 22);
  60.  
  61. personRepository.save(p1);
  62. personRepository.save(p2);
  63. personRepository.save(p3);
  64.  
  65. Iterator<Person> people = personRepository.findAll().iterator();
  66. while (people.hasNext()) {
  67. Person temp = people.next();
  68. System.out.println(temp);
  69. }
  70. }
  71. }
  72.  
  73. Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.devs4j.spring.data.repositories.PersonRepository' available
  74.  
  75. @Configuration
  76. @EnableJpaRepositories("com.devs4j.spring.data.repositories")
  77. public class JpaConfiguration {
  78.  
  79. }
  80.  
  81. EnableJpaRepositories cannot be resolved to a type
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement