@EnableJpaRepositories отсутствует в весенней загрузке 2.1.4.RELEASE - PullRequest
0 голосов
/ 30 апреля 2019

Я создал проект с помощью весенней загрузки 2.1.4.RELEASE со следующими зависимостями:

<dependencies>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.1.4.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

У меня есть следующие сущность и репозиторий:

@Entity
public class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "name")
    private String name;

    @Column(name = "last_name")
    private String lastName;

    @Column(name = "age")
    private Integer age;

    @Column(name = "createdAt")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdAt;
...
}

PersonRepository.java

@Repository
public interface PersonRepository extends CrudRepository<Person, Integer> {

}

Вот мой класс Application:

@SpringBootApplication
public class SpringDataApplication {

    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext context = SpringApplication.run(SpringDataApplication.class, args);
        PersonRepository personRepository = context.getBean(PersonRepository.class);
        Person p1 = new Person("Juan", "Camaney", 55);
        Person p2 = new Person("Arturo", "Lopez", 33);
        Person p3 = new Person("Pancho", "Coscorin", 22);

        personRepository.save(p1);
        personRepository.save(p2);
        personRepository.save(p3);

        Iterator<Person> people = personRepository.findAll().iterator();
        while (people.hasNext()) {
            Person temp = people.next();
            System.out.println(temp);
        }
    }
}

Если я выполняю свое приложение, я получаю следующую ошибку:

Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.devs4j.spring.data.repositories.PersonRepository' available

Решение этой проблемы - добавлениеследующий класс конфигурации:

@Configuration
@EnableJpaRepositories("com.devs4j.spring.data.repositories")
public class JpaConfiguration {

}

Но я получаю ошибку:

EnableJpaRepositories cannot be resolved to a type

Если я понижаю до 2.0.5.RELEASE все работает нормально.

Я в замешательстве, потому что когда я проверяю следующую весеннюю документацию https://docs.spring.io/spring-data/jpa/docs/2.1.6.RELEASE/reference/html/ Я вижу, что она все еще использует @EnableJpaRepositories ("com.acme.repositories")

Я что-то делаюнеправильно?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...