> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/29.-working-with-sql-databases/29.3.-jpa-and-spring-data/29.3.1.-entity-classes.md).

# 29.3.1. 实体类

通常，JPA实体类被定义到一个`persistence.xml`文件。在Spring Boot中，这个文件被“实体扫描”取代。默认的，Spring Boot会查找主配置类（被`@EnableAutoConfiguration`或`@SpringBootApplication`注解的类）下的所有包。

任何被`@Entity`，`@Embeddable`或`@MappedSuperclass`注解的类都将被考虑。一个普通的实体类看起来像这样：

```java
package com.example.myapp.domain;

import java.io.Serializable;
import javax.persistence.*;

@Entity
public class City implements Serializable {

    @Id
    @GeneratedValue
    private Long id;

    @Column(nullable = false)
    private String name;

    @Column(nullable = false)
    private String state;

    // ... additional members, often include @OneToMany mappings

    protected City() {
        // no-args constructor required by JPA spec
        // this one is protected since it shouldn't be used directly
    }

    public City(String name, String state) {
        this.name = name;
        this.country = country;
    }

    public String getName() {
        return this.name;
    }

    public String getState() {
        return this.state;
    }
    // ... etc
}
```

**注** 你可以使用`@EntityScan`注解自定义实体扫描路径，具体参考[章节 79.4，从Spring配置分离`@Entity`定义](https://github.com/jack80342/spring-boot/tree/25350df33f8edd68b50ff6f6e1258c9df4f67d67/IX.%20‘How-to’%20guides/79.4.%20Separate%20@Entity%20Definitions%20from%20Spring%20Configuration.md)。
